What's right answer for this question?

WHICH TWO CANNOT DIRECTLY CAUSE A THREAD TO STOP EXECUTING:1. Exiting from a synchronized block.2. Calling the wait method on an object3. Calling notify method on an object4. Calling setPriority method on a thread object.
[256 byte] By [skp71a] at [2007-11-27 10:10:15]
# 1
What do you think, and why?
jverda at 2007-7-13 0:46:59 > top of Java-index,Java Essentials,Java Programming...
# 2
For the record, I think it's a lousy question. To my mind, only one of them can. So either I'm mistaken (a definite possibility), or the author of the question is mistaken, or the question is just very poorly prhased with the "directly cause a thread to stop executing."
jverda at 2007-7-13 0:46:59 > top of Java-index,Java Essentials,Java Programming...
# 3
42What do I win?
floundera at 2007-7-13 0:46:59 > top of Java-index,Java Essentials,Java Programming...
# 4

Jverd is right in saying that this is a lousy question! I would read "stop execution" as "pause execution", for my convenience. :-)

I may be terribly wrong in this, but my answer to this question would be 1 and 3. Here's why:

1. Exiting from a synchronized block - The thread just released a lock on an object. Why should it pause execution?

2. Calling the wait method on an object - Yes, the thread will be added to the wait set of the object, and will require some other thread to invoke the notify( ) method on the object, so that it can wake-up, contend and then resume execution.

3. Calling notify method on an object - The thread need not pause execution as soon as it calls the notify( ) method. It releases the object lock at its own discretion. Only after the lock release, will it pause execution.

4. Calling setPriority method on a thread object - The higher priority thread may win the confidence of the thread scheduler :-)

Thanks and Regards,

Kumar.

kumar_iyera at 2007-7-13 0:46:59 > top of Java-index,Java Essentials,Java Programming...