• Post Reply Bookmark Topic Watch Topic
  • New Topic

why thread can't be restarted?

 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
can anybody explain to me that why we can't restart the same thread using start() method again on it once it has finished the execution.
because sometime i think it is necessary to do so when our thread is maintaing information from different places and if we recreate the thread to re-run it then we have to have all that information which might be not possible or difficult to get.
regards
maulin
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread represents an operating system thread - and once an OS thread has expired, you can't revive it, all you can do is create a new one. If your code needs restarting, it clearly is not a kind of Thread. So it should not extend Thread. It might perhaps be Runnable, so you can easily run it in a fresh Thread.
For more discussion on this topic, see this recent thread.
- Peter
[This message has been edited by Peter den Haan (edited December 04, 2001).]
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maulin
Keep in mind that you can still access a threads methods and members after it has run. If your Thread is running and getting data and processing it after its run method has returned you can still get at that data through the Thread object you created. Is that what you need to do or does it have to do everything over again?

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Peter & Dave,
thanks a lot for your help. it was a good help. it makes sense to work with Runnable if we want the object ref. to be the same everytime we want to run a thread.
regards
maulin.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!