void waitForSignal(){
Object obj=new Object();
synchronized(Thread.currentThread()){
obj.wait();
obj.notify();}
}what statement is ture?
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 replace with "((Thread)obj).wati()".
E.a call to notify() or notifyAll() from another thread may cause this method to complete normally.
Object obj=new Object();
synchronized(Thread.currentThread()){
obj.wait();
obj.notify();}
}what statement is ture?
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 replace with "((Thread)obj).wati()".
E.a call to notify() or notifyAll() from another thread may cause this method to complete normally.
解决方案 »
- webservice方法中调用另外一个webservice接口的问题
- 如何对窗口中的Component进行排版
- Integer.valueOf("123").intValue(); 多方法连写的组合顺序是从左向右吗?
- JAR Classpath 如何设置?
- 连数据库的程序,打成Jar包后的提示连接数据库失败
- 载入图片,非常奇怪
- 要怎样学习JAVA 源代码啊 ?
- 请教,怎么做客户需求
- 哪位老大能给出一个web服务器的是现代吗?
- 想找一个java 做的文件下载程序(最好用URL类吧),那位有这方面的程序或代码?100分必送
- 跪求 ~~~关于JTextPane做分页编辑器的问题!!!急急!!
- jdk 中各个文件夹的意思是什么?
在非法或不适当的时间调用方法时产生的信号。换句话说,即 Java 环境或 Java 应用程序没有处于请求操作所要求的适当状态下。synchronized锁住的是当前线程这个对象,而当前线程正在使用中,所以属于非法或不适当的时间表调用.不知道解释的对否,听高手的详解.:)
obj.wait();
obj.notify();}
====================obj.wait()是用于把当前线程抛入对象池等待,直到其它线程调用此对象的notify()方法将该线程唤醒....后面紧接着来了个obj.notify() 处于等待状态下的线程调用notify()方法唤醒自身?属于非法调用
应该抛出java.lang.IllegalMonitorStateException异常因为你在调用obj.wait();的时候并没有对obj锁定,必须
synchronized(obj)之后才可以调用obj.wait()