What statements are true concerning the method notify() that is used in conjunction with wait()?
Select all valid answers.
a) if there is more than one thread waiting on a condition, only the thread that has been waiting the longest is notified
b) if there is more than one thread waiting on a condition,there is no way to predict which thread will be notifed
c) notify() is defined in the Thread class
d) it is not strictly necessary to own the lock for the object you invoke notify() for
e) notify() should only be invoked from within a while loop
这个应该是scjp的题目。大家看看应该选哪个,我英文还不打过关啊。

解决方案 »

  1.   

    英语不好。我大概翻译一下(担心误人子弟#-_-)。有错误欢迎大家指正。
    1那些关于notify()和wait()方法联合使用的描述是正确的?
    a)如果有多个等待该锁的线程,只有那个等待时间最长的线程被通知。(错误,是任意选出一个通知的)
    b)如果有多个等待该锁的线程,没有方法知道那个线程将被通知。
    c)notify() 定义在Thread 类中。(notify定义在Object中)
    d)当调用notify()不是必须获得该对象的锁。(错误,必须获得锁)
    e)notify()仅应该在循环中调用。(错误)