wood burning stoves*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes thread start in k&b Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "thread start in k&b" Watch "thread start in k&b" New topic
Author

thread start in k&b

atiqur rahman
Greenhorn

Joined: Aug 30, 2003
Posts: 10
in page 505
If you have a reference to a thread t, and its run() method has finished, you can't say t.start(); you'll get a big fat runtime exception.
in page 508
If you invoke start() on a dead Thread instance, you'll get a runtime(not compiler) exception.
in page 536
You can call start() on a Thread object only once. If start() is called more than once on a Thread object, it will throw a RuntimeException.
Now consider the following code:

This program gives a runtime exception but if i remove the comment then it runs fine. When the comment is removed then the new thread must be dead, why should i don't get a runtime exception???
[ April 12, 2004: Message edited by: Barry Gaunt ]
VP Jain
Ranch Hand

Joined: Feb 11, 2004
Posts: 81
hi,
You wont get a runtime exception when u remove the t.join().
Try executing the following example and i am sure u will be clear.

If you run the above example then the following will be the output
NameRunnable running
Run by Frudo for the ith 0time
NameRunnable running
Run by Frudo for the ith 1time
NameRunnable running
Run by Frudo for the ith 2time
NameRunnable running
Run by Frudo for the ith 3time
NameRunnable running
Run by Frudo for the ith 4time

and thread name with "Gandalf" will never be executed
Regards
.PAL.
[ April 12, 2004: Message edited by: Barry Gaunt ]

SCJP SCWCD SCBCD <br /> <br />what u do in life echos in eternity!
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
This was discussed a couple of days ago in this thread.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: thread start in k&b
 
Similar Threads
K&B Threads: subtle detail calling start() important?
Join method on thread
Question on Thread
Threads
Thread Q from Sierra & Bates SCJP Study Guide