Hi All,
I have a doubt in Threads. What happens when a
thread does not call notify()? Yestarday I had read in one of the posts that if a thread does not call notify(), thread can wakeup itself in such a condition(But this behavior is not guranteed). But when I was solving question from K&B book chapter 'Threads' question number 9 as given below. The explination given is "there will be no return from the wait call because
no other thread will notify the main thread". Can anybody please tell me which one is the correct answer.
Given the following
1. public class WaitTest {
2. public static void main(
String [] args) {
3. System.out.print("1 ");
4. synchronized(args){
5. System.out.print("2 ");
6. try {
7. args.wait();
8. }
9. catch(InterruptedException e){}
10. }
11. System.out.print("3 ");
12. } }
What is the result of trying to compile and run this program?
A. It fails to compile because the IllegalMonitorStateException of wait() is not dealt
with in line 7.
B. 1 2 3
C. 1 3
D. 1 2
E. At runtime, it throws an IllegalMonitorStateException when trying to wait.
F. It will fail to compile because it has to be synchronized on the this object.
Thanks
Aparna