package student;
class teacher{
public synchronized void say(){
System.out.println("在说话");
//Thread.sleep(100000);
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("我醒了@");
}
public synchronized void sayhello(){
System.out.println("我在说hello");
}
}
class thread1 implements Runnable{
public static teacher tea=new teacher();
public void run(){
try {
tea.say();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class Demo{
public static void main(String[] args){
thread1 tre=new thread1();
new Thread(tre).start();
try {
Thread.sleep(1222);
} catch (InterruptedException e) {
e.printStackTrace();
}
thread1.tea.sayhello();
thread1.tea.notify();//这里提示错误了!
}
}
提示是:java.lang.IllegalMonitorStateException异常!、
请大虾看看!
class teacher{
public synchronized void say(){
System.out.println("在说话");
//Thread.sleep(100000);
try {
this.wait();
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("我醒了@");
}
public synchronized void sayhello(){
System.out.println("我在说hello");
}
}
class thread1 implements Runnable{
public static teacher tea=new teacher();
public void run(){
try {
tea.say();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public class Demo{
public static void main(String[] args){
thread1 tre=new thread1();
new Thread(tre).start();
try {
Thread.sleep(1222);
} catch (InterruptedException e) {
e.printStackTrace();
}
thread1.tea.sayhello();
thread1.tea.notify();//这里提示错误了!
}
}
提示是:java.lang.IllegalMonitorStateException异常!、
请大虾看看!
解决方案 »
- 求一个简单的java的socket程序,基于二进制传输的代码
- windows server 2003 runDll32命令 在dos运行一闪即没,在线等!!!
- 高手们给点建议!
- 如何将解析XML的数据用JTABLE来设置
- 【竞赛奖励】SageZk 、scf37、sort_superdullwolf 每人获得100专家分,请进来收取
- PreparedStatement.setNull()的问题
- bean打包的问题
- 使用JDOM时出现问题:The encoding "GBK" is not supported
- 本人刚刚学JAVA,求变量转换集。出分50,希望各位兄第能帮一下。
- jdbc 里怎么取得存储过程里的return值,不是output值
- java对象实例化【新手上路】
- 为什么JAVA编程里把主函数放在定义的类中??
否则就是报这个错