public class Test {
public static final String moudle = Test.class.getName();
public Test() {
}
/**
* @param args
*/
public static void main(String[] args) throws Exception{
new Thread(new InputThread()).start();
new Thread(new InputThread()).start();
new Thread(new InputThread()).start();
}
}
class InputThread extends Thread{
private static Object lock = new Object();
public void run(){
synchronized(lock){
System.out.println("ddddd");
try {
//lock.wait();
Thread.sleep(100000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
去掉了也是正确的呀。。
进入第一个线程,,打印出ddddd,然后第一个线程立马wait了,就丢失了同步锁lock。
第二个进来,就可以拿到同步锁了,就继续打印ddddd。然后同样wait.
第三进来 ,,效果一样。。
最后,,大家都wait在那,,程序不停运行下去。。
你这个不是要new Thread(new InputThread()).start(); 等待一定时间才执行么,我看了,有效果的呀。。
Thread.sleep(100000); 这个是不是太长了,100秒?
[code="java"]Thread.sleep(100000);[/code]
这个是让主线程sleep了
应该是this.sleep(100000)