Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

NotSerializableException  RSS feed

 
Ravi Kumar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am new to java.io package.
I am trying to persist the java.lang.Process object into file system by using ObjectOutputStream.While executing this statement ois.writeObject(java.lang.Process) i am getting this exception.

java.io.NotSerializableException: java.lang.ProcessImpl
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1075)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:291)
at com.ms.rfid.kernel.RmiServerAgent.startRfidServer(RmiServerAgent.java:128)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
at sun.rmi.transport.Transport$1.run(Transport.java:153)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
at java.lang.Thread.run(Thread.java:595)

Can anybody help to solve this problem please.......

this is the sample code
{
spawnedProcess = Runtime.getRuntime().exec(cmdArray, null, null);
fos = new FileOutputStream("process.pro");
oos = new ObjectOutputStream(fos);
oos.writeObject(remoteProcess);
}

Regards,
Ravi
 
Joe Ess
Bartender
Posts: 9426
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For ObjectOutputStream to process a class, it must implement java.io.Serializable. See the API documentation for ObjectOutputStream and Serializable for more details.
 
Ravi Kumar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your s response. How can i serialize java.lang.Process object.
Please help me out on this.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i serialize java.lang.Process object.

You can't. A Process object is applicable only to the machine where it's running (it's similar to a File object in that regard), so it can't be serialized (which would enable the serialized representation to be used elsewhere).
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can i serialize java.lang.Process object.

Why do you need to persist a process?
It does not make sense to persist a process as it is just an execution of a command, you can not freeze the state of a process and re-run at a different time. So, what is the reason for trying to do the same?
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Process is a java class and if this doesnot implement java.io.Serializable interface then you cannot serialize it.

You are free to decide which classes written by you need to be serialized.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!