This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads" Watch "threads" New topic
Author

threads

Sahil Manchanda
Ranch Hand

Joined: Jul 24, 2012
Posts: 41

can anybody tell me why this code throws an exception?

Sharmistha Sarkar
Ranch Hand

Joined: Dec 18, 2012
Posts: 44
Perhaps you have got this exception
Exception in thread "main" foojava.lang.IllegalThreadStateException
at java.lang.Thread.start(Unknown Source)

You have started the thread twice. It is never legal to start the thread more than one time. Once the thread completes it's execution it will never restarted.
you can remove the 2nd t.start(); from code.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6657
    
    5

You might also be interested in learning about the lifecycle of threads


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: threads
 
Similar Threads
Question on threads
Concurrency with 2-cores-CPU
gives IllegalThreadStateException why?
Question on Thread
regarding threads