wood burning stoves 2.0*
The moose likes Java in General and the fly likes Thread Start() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Thread Start() method" Watch "Thread Start() method" New topic
Author

Thread Start() method

ajit a
Greenhorn

Joined: Apr 17, 2002
Posts: 7
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

Joined: Aug 08, 2002
Posts: 89
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

Joined: Jun 06, 2002
Posts: 1056
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.


Ron Newman - SCJP 1.2 (100%, 7 August 2002)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Thread Start() method