当前位置: 技术问答>java相关
一道scjp题,简单给我解释一下,用中文
来源: 互联网 发布时间:2015-11-20
本文导语: Which two can directly cause a thread to stop executing? (Choose Two) A. Exiting from a synchronized block. B. Calling the wait method on an object. C. Calling the notify method on an object. D. Calling the notifyAll method on an object. E. Cal...
Which two can directly cause a thread to stop
executing? (Choose Two)
A. Exiting from a synchronized block.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the setPriority method on a thread object.
the answer is B,E,
但我不明白,哪位给我解释一下?
executing? (Choose Two)
A. Exiting from a synchronized block.
B. Calling the wait method on an object.
C. Calling the notify method on an object.
D. Calling the notifyAll method on an object.
E. Calling the setPriority method on a thread object.
the answer is B,E,
但我不明白,哪位给我解释一下?
|
1. Synchronized block是给对象上锁,与线程运行与否没有直接关系;
2. wait方法会使线程停下来,直到该对象执行notify或notifyAll方法;
3. notify和notifyAll方法会让原来wait的线程进入runnable状态,但不会立刻让当前线程停止;
4. setPriority方法可以让当前线程停止。
2. wait方法会使线程停下来,直到该对象执行notify或notifyAll方法;
3. notify和notifyAll方法会让原来wait的线程进入runnable状态,但不会立刻让当前线程停止;
4. setPriority方法可以让当前线程停止。