wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes K&B Threads: subtle detail calling start() important? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "K&B Threads: subtle detail calling start() important?" Watch "K&B Threads: subtle detail calling start() important?" New topic
Author

K&B Threads: subtle detail calling start() important?

Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
Hi,

In K&B Chapter 9 on threads is says:
Dead A thread is considered dead when its run()
method completes. It may still be a viable Thread object, but
it is no longer a separate thread of execution. Once a thread
is dead, it can never be brought back to life! (The whole "I
see dead threads" thing.) If you invoke start() on a dead Thread
instance, you�ll get a runtime (not compiler) exception.


The following code does not give me an java.lang.IllegalThreadStateException


it compiles and runs fine.

The answer to this is (from "Java Threads, 2nd Edition" by S. Oaks
and H. Wong, Chapter 2.6)

What happens when you try to restart a thread? The answer is
that it actually depends on when you restart it
...
it actually takes time for a thread to stop.
...
If the start() method is called after the stopping thread has actually
stopped, nothing happens: the thread object is in a state where it
cannot be restarted


Can an exam question go into such low level details?

Cheers,

Gian Franco
[ May 20, 2004: Message edited by: Gian Franco Casula ]

"Eppur si muove!"
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Did you read this thread?

And from the books errata:

Page 505,Second paragraph2/07/03

Change:
.. method has finished, you can't say t.start(); you'll get a big fat runtime exception.
To:
.. method has finished, calling t.start() won't restart it.



The errata is here.
[ May 20, 2004: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Gian Franco
blacksmith
Ranch Hand

Joined: Dec 16, 2003
Posts: 977
Thanks Barry, I didn't see that topic-thread before.

Cheers,

Gian Franco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: K&B Threads: subtle detail calling start() important?
 
Similar Threads
When the execution ends?
join() in thread...continues....
Threads doubt??
Threads
threads