Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Thread Start() method

 
ajit a
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all...
regarding thread ...
why cant i start thread again?
Thread t = new Thread()
t.start(); // calls run method of this thread
t.start();// while this does not call run method
why its so that we can only call start method only once?
thx in advance.
Ajit.
 
Anirban dutta
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ajit,
You must be getting IllegalThreadStateException. This is due to because java always checks for the state of a thread---whether it is running, suspended, or dead---if you do any operations when the thread is in any of the states, but that operation is illegal or senseless in that state then such exception is thrown. In your case u r trying to start a thread which is already started which is senseless, hence the exception. If u r trying to spawn 2 seperate threads then make 2 different thread class objects and call start on them seperately.
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Starting a thread calls its run() method. Once the run() method completes, the thread is dead -- all you can do is join() it. You can't restart it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic