作者: 裤裆里的温柔、 时间: 2014-7-31 16:37
class Suo
{
public static void jiaSuo()
{
System.out.println("我加锁了<--->");
}
}
这个干么用的作者: masai158 时间: 2014-7-31 16:53
public class Test014
{
static int count = 1000000;
public static void main(String[] args)
{
long startTime = System.currentTimeMillis();
Object obj = new Object();
Thread ck1 = new Thread(new Window1(obj),"窗口11111");
Thread ck2 = new Thread(new Window2(obj),"窗口222");
Thread ck3 = new Thread(new Window3(obj),"窗口33333333333");
ck1.start();
ck2.start();
ck3.start();
try
{
ck1.join();
ck2.join();
ck3.join();
} catch (InterruptedException e) {
卖一张就睡觉。等待其他线程唤醒。
1卖了,睡觉。。只 唤醒2.
2卖了,睡觉。。。只 唤醒3
3卖了,睡觉。。只唤醒1作者: 大★宝 时间: 2014-8-7 11:31
知识回顾,赞作者: laibin2 时间: 2014-8-7 11:42
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);