• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

thread start in k&b

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This was discussed a couple of days ago in this thread.
 
reply
    Bookmark Topic Watch Topic
  • New Topic