This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
This is a question from examlab. It outputs Ex-B and then an exception.
Although a nice explanation is given in examlab. But i could not understand the interrupt
call on line 2.
According to me the working should be :
Line 1 should start the thread t and then doDelay should make t sleep for 1 sec.
Meanwhile main calls dodelay() which should put main to sleep.
But main should wake you before t and then call interrupt. This must make t throw
IntrruptedException and print Ex-A. Now thread t should resume and call halt() and
calling wait() should throw Exception and print Ex-B..
There is a slight trick here, we actually started thread t and called interrupt on a. This is why the call to a.interrupt() didn't throw an exception. If you call t.interrupt() instead of a.interrupt(), you'll get "Ex-A" in the output...