Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

start the thread

 
SrinivasaRao Swarna
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,


We can start thread two times ?is it posible?How can do?


Thanks&Regards
srinivas
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is what the javadoc of start method says:


It is never legal to start a thread more than once. In particular, a thread may not be restarted once it has completed execution.

Throws:
IllegalThreadStateException - if the thread was already started.


It is always recommended to RTFM (Read the f#$%ing manual)
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's what you can do instead. Put your code in a Runnable and run it on two threads:

See how we executed the run() method in MyRunnable twice? Is that the effect you wanted? If so, we can also do some neat stuff with Thread pools.
[ September 12, 2007: Message edited by: Stan James ]
 
paritosh ranjan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
threads are same as human beings
they take birth once and die once
we never take birth twice
same is the case with threads
once the thread is started the thread can't be started again
even after the thread finishes executing and reaches dead state
start() can't be called on the dead thread
like once humans are dead,they can't be made alive
if you try to start the same thread again,you will get a IllegalStateException
 
Peter Chase
Ranch Hand
Posts: 1970
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by paritosh ranjan:
threads are same as human beings
they take birth once and die once


Have you never seen Dawn (or Shaun) of the Dead?!
 
paritosh ranjan
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what does that mean??
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look at the wikipedia articles on Dawn of the Dead and its comedy counterpart, Shaun of the Dead and you will understand what this all means: poor joke.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic