wood burning stoves
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 Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "threads" Watch "threads" New topic


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: 47
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

Joined: Feb 24, 2006
Posts: 6662

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
It's not a secret anymore!