Serializing Runnables
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Daelin_Lunaeri
Posted On:   Tuesday, November 29, 2005 09:42 AM

I have a Runnable object I want to serialize while it is being used in a live thread. I want to be able to deserialize it later and place it in a new thread and get it running again. Is this possible? I do understand that you cannot restart a dead thread, but I thought it might be possible to place an old runnable in a new thread and make it run. However, it doesn't seem to want to run when I deserialize it, though I get no exceptions. ObjectOutputStream oos = new ObjectOutputStream( new FileOutputStream("filename.file")); oos.writeObject(myRunnable); oos.close(); // Then, later read back the object and put it in a new thread ObjectInputStream ois = new ObjectInputStream( ne   More>>

I have a Runnable object I want to serialize while it is being used in a live thread. I want to be able to deserialize it later and place it in a new thread and get it running again. Is this possible?


I do understand that you cannot restart a dead thread, but I thought it might be possible to place an old runnable in a new thread and make it run. However, it doesn't seem to want to run when I deserialize it, though I get no exceptions.


			
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("filename.file"));
oos.writeObject(myRunnable);
oos.close();

// Then, later read back the object and put it in a new thread

ObjectInputStream ois = new ObjectInputStream(
new FileInputStream("filename.file"));
myRunnable = (RunnableClass)ois.readObject();
Thread t = new Thread(myRunnable);
t.start();
ois.close();
   <<Less

Re: Serializing Runnables

Posted By:   ankush_purwar  
Posted On:   Thursday, December 1, 2005 03:02 AM

You can call wait, stop and notfy methods on thread.
But once your thread has been finished. you can't alive it.

For that you must have to create a new thread.

Thread is an execution unit of the program, it is not designed for storing the data. So there is no sense to serialize the Thread.
About | Sitemap | Contact