Duo duo = new Duo();
Duo duo1 = new Duo();
Duo duo2 = new Duo();
Thread s = new Thread(duo);
Thread s2 = new Thread(duo1);
Thread s3 = new Thread(duo2);
创建了三个资源,三个线程都在执行不同的资源,所以
notifyAll();
try {
wait();
} catch (Exception e) {
}
都不能唤醒其他两个线程,所以都是卖了一张票就wait()了.
解决方法,只能new 一个DUo,让三个线程执行一个资源.
重点 Duo duo = new Duo();
Thread s = new Thread(duo);
Thread s2 = new Thread(duo);
Thread s3 = new Thread(duo); |