多线程wait方法使用问题

a15973032315 2014-03-16 10:26:14
public class test2 extends Thread {
public synchronized void run()
{
start();
System.out.println(System.currentTimeMillis());
try {
wait(1000);
notify();
System.out.println(System.currentTimeMillis());
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public static void main(String[] args) {
test2 t=new test2();
t.run();
}
}

我就是想在wait之前打印下时间,之后也打印下时间,但是不知道为什么老是报错Exception in thread "Thread-0" java.lang.IllegalThreadStateException,求大神指点下。。。
...全文
92 1 打赏 收藏 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
kanorl 2014-03-16
  • 打赏
  • 举报
回复
线程启动的方法是thread.start(),而不是直接调用run().run()方法里不要再调用start()

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧