Question 132
Given:
7. void waitForSignal() {
8. Object obj = new Object();
9. synchronized (Thread.currentThread()) {
10. obj.wait();
11. obj.notify();
12. }
13. }
Which is true?
A. This code may throw an InterruptedException.
B. This code may throw an IllegalStateException.
C. This code may throw a TimeoutException after ten minutes.
D. This code will not compile unless “obj.wait()” is replaced with
“((Thread) obj).wait()”.
E. Reversing the order of obj.wait() and obj.notify() may cause this
method to complete normally.
F. A call to notify() or notifyAll() from another thread may cause this
method to complete normally.答案是B。IllegalStateException怎么来的?
Given:
7. void waitForSignal() {
8. Object obj = new Object();
9. synchronized (Thread.currentThread()) {
10. obj.wait();
11. obj.notify();
12. }
13. }
Which is true?
A. This code may throw an InterruptedException.
B. This code may throw an IllegalStateException.
C. This code may throw a TimeoutException after ten minutes.
D. This code will not compile unless “obj.wait()” is replaced with
“((Thread) obj).wait()”.
E. Reversing the order of obj.wait() and obj.notify() may cause this
method to complete normally.
F. A call to notify() or notifyAll() from another thread may cause this
method to complete normally.答案是B。IllegalStateException怎么来的?
解决方案 »
- jpa一对多条件查询
- 当一个对象被当作参数传递到一个方法中,是何种传递
- java 线程的notify和wait不配套使用问题
- 谁能帮我做一个名片管理系统的项目
- 急!求正则表达式
- 怎样才能做出象windows搜索文件之后的那个效果?就是将搜索出来的文件,按各种信息列出来,比如有文件类型,文件的位置(能不能用jb8做出
- 有谁知道JBuilder6个人版的序列号吗? 如果能用的话,200分!
- 很奇怪的问题,关于类方法函数传递?请看代码:(特邀路人甲、天生不笨等高手)
- 哪里有java的开发工具下载?谢谢了!!
- 一个关于子类自动调用父类构造方法的问题,百思不得其解
- 继承覆盖吗?
- 线程出错后是否立即停止?
应该由别的线程发出,是线程间通信,是这样吧?那是obj.wait()等的时间太长了,导致错误还是obj.notify()发现没有线程在等他,导致的?
wait(0);
}
wait方法可能抛出InterruptedException异常,这里没有捕捉,编译也不可能通过吧。