• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

NotSerializableException

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic