| Author |
thread question required
|
Tom Tolman
Ranch Hand
Joined: Sep 02, 2004
Posts: 83
|
|
I interpret "Exiting from a synchronized block." to mean that the thread exits from a block of code which has the lock on an object- thereby allowing other threads to access this objects lock (and execute synchronized blocks on it as well) I don't interpret it to mean the program ends. Nor does it mean that the currently executing thread will necessarily suspend- why would it? What if you had a single thread application with lots of synchronized blocks in it- would the thread cease (for no other thread) simply because it had left a synchronized block? A synchronized block does not imply anything about the thread being run. A thread can be put into a wait state even if it is holding object locks.
|
 |
Inuka Vincit
Ranch Hand
Joined: Aug 10, 2004
Posts: 175
|
|
Tom yeah I was about to correct him. You question is clear. a thread leaving the syncronized block mearly means that the thread gave up the lock and not that its going to stop running. Only the VM will decide that. check this tutorial out it explains things pretty clearly http://java.sun.com/docs/books/tutorial/essential/threads/index.html
|
MCP (C# application dev 70-316) 860<br />SCJP 1.4 100% SCJD (URLyBird) 378<br />MAD 100% nuts
|
 |
PETER CARTER
Ranch Hand
Joined: Aug 28, 2004
Posts: 70
|
|
Which two can directly cause a thread to stop executing? (Choose Two) A. Exiting from a synchronized block. B. Calling the wait method on an object. C. Calling the notify method on an object. D. Calling the notifyAll method on an object. E. Calling the setPriority method on a thread object. Answer: B, E Why A is wrong ?? Thanks!!!
|
 |
Colin Fletcher
Ranch Hand
Joined: Sep 10, 2004
Posts: 200
|
|
One way to look at it is: The exit directive indicates the program/application should stop running. The application will exit, why would it matter if you "close the resource" in the finally block?
|
SCJP 1.4 SCWCD 1.4
|
 |
Mohit Agarwal
Ranch Hand
Joined: Mar 30, 2004
Posts: 88
|
|
Why alternate E is correct . please throw some light on this. Mohit Would be SCJP.
|
 |
Louie van Bommel
Ranch Hand
Joined: Aug 17, 2004
Posts: 76
|
|
Originally posted by Mohit Agarwal: Why alternate E is correct . please throw some light on this. Which two can directly cause a thread to stop executing? (Choose Two) A. Exiting from a synchronized block. B. Calling the wait method on an object. C. Calling the notify method on an object. D. Calling the notifyAll method on an object. E. Calling the setPriority method on a thread object. Answer: B, E
The thread scheduler will frequently (but certainly not always) schedul OUT a thread if a thread of higher priority is available (runnable) and make the HIGHER priority thread execute. (running) If the thread which currently has the processor is changed to a lower priority, a higher priority thread may be scheduled to execute by the thread scheduler. It's debatable if this can be viewed as "directly cause a thread to stop executing" because it's the THREAD SCHEDULER that's directly causing the thread to stop executing. (Unlike the test, I'm making assumptions about the test-writer's INTENTION vs. the wording).
|
 |
 |
|
|
subject: thread question required
|
|
|