• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Thread Start() method

 
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.
 
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.
 
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.
 
Today you are you, that is turer than true. There is no one alive who is youer than you! - Seuss. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic