Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

thread start in k&b

 
atiqur rahman
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This was discussed a couple of days ago in this thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic