• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

2nd time thread is neither running nor throwing exception, why?

 
Ranch Hand
Posts: 257
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

above script is printing only one "hello". second start() is not printing hello why?
I thought calling same thread twice cause IllegalThreadState exception. but it is not giving exception also.
(code tags added - use edit button to see how to do it)
[ April 28, 2004: Message edited by: Barry Gaunt ]
 
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you comment the join part of code, it is going to throw the error that you are expecting. But i am also surprised what difference join is making it ignore the second 'start'
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deleted by request (next down).
Next time use the EDIT thingie (paper/pencil icon)
[ April 28, 2004: Message edited by: Barry Gaunt ]
 
Karel KoboojBot
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First of all, sorry about reply above (had a slight problem with my tab key ). Could one of the administrators delete this please ?

This code will print "hello" during the run of the thread because of the first start() invocation.
The second time you call start() on this thread, that thread will already be dead because you have a join in your code. The implementation of JVM 1.4 allows you to do this, but it will not run the thread again, because a dead thread stays dead. Hence, no second printing of "hello".
Now the strange part. Even though the JVM 1.4 implementation does not throw an exception (you would expect a IllegalThreadStateException), if you get a question on the exam about it, you should say that it does throw one (because it says so in the official API).
Hope this helps.
 
Sekhar Kadiyala
Ranch Hand
Posts: 170
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Isn't it some sort of bug?
Bert/Kathy, Do you guys have any idea?
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic