Get your CodeRanch badge!*
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 Java 8 in Action this week in the Java 8 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
gives IllegalThreadStateException why?
Concurrency with 2-cores-CPU
Question on Thread
regarding threads