WEB开发网
开发学院软件开发Java Java 多线程同步问题的探究(四、协作,互斥下的协... 阅读

Java 多线程同步问题的探究(四、协作,互斥下的协作——Java多线程协作(wait、notify、notifyAll))

 2010-05-14 00:00:00 来源:WEB开发网   
核心提示: 最后,我们构造汉堡店,Java 多线程同步问题的探究(四、协作,互斥下的协作——Java多线程协作(wait、notify、notifyAll))(7),让这个故事发生:publicclassHambergShop{Waiterwaiter=newWaiter();HambergFifohamb

最后,我们构造汉堡店,让这个故事发生:

public class HambergShop {
    Waiter waiter = new Waiter();
    HambergFifo hambergPool = new HambergFifo();
    Customer c1 = new Customer(waiter, hambergPool);
    Customer c2 = new Customer(waiter, hambergPool);
    Customer c3 = new Customer(waiter, hambergPool);
    Cooker cooker = new Cooker(waiter, hambergPool);
    public static void main(String[] args) {
        HambergShop hambergShop = new HambergShop();
        Thread t1 = new Thread(hambergShop.c1, "Customer 1");
        Thread t2 = new Thread(hambergShop.c2, "Customer 2");
        Thread t3 = new Thread(hambergShop.c3, "Customer 3");
        Thread t4 = new Thread(hambergShop.cooker, "Cooker 1");
        Thread t5 = new Thread(hambergShop.cooker, "Cooker 2");
        Thread t6 = new Thread(hambergShop.cooker, "Cooker 3");
        t4.start();
        t5.start();
        t6.start();
        try {
            Thread.sleep(10000);
        } catch (Exception e) {
        }
        t1.start();
        t2.start();
        t3.start();
    }
}

上一页  2 3 4 5 6 7 8  下一页

Tags:Java 线程 同步

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接