void waitForSignal() { Object obj = new Object(); synchronized (Thread.currentThread()) { obj.wait(); obj.notify(); } }
以下哪一个描述是正确的?
void waitForSignal() { Object obj = new Object(); synchronized (Thread.currentThread()) { obj.wait(); obj.notify(); } }
需要处理InterruptedException。
代码能编译但可能运行时抛出IllegalStateExcepion。
运行10分钟后代码抛出TimeOutException。
需要把obj.wait()替换为((Thread) obj).wait()后代码才能通过编译。
把obj.wait()和obj.notify()这两句调换一下位置,能使代码执行。