相关疑难解决方法(0)

在Object类中放置wait(),notify()方法的概念

我只是很难有时间去了解背后把概念wait()Object类.为了这个问题,请考虑是否wait()notifyAll()Thread课堂上.

class Reader extends Thread {
    Calculator c;
    public Reader(Calculator calc) {
        c = calc;
    }

    public void run() {
        synchronized(c) {                              //line 9
        try {
            System.out.println("Waiting for calculation...");
            c.wait();
        } catch (InterruptedException e) {}
            System.out.println("Total is: " + c.total);
        }
    }

    public static void main(String [] args) {
        Calculator calculator = new Calculator();
        new Reader(calculator).start();
        new Reader(calculator).start();
        new Reader(calculator).start();
        calculator.start();
    }
}

class Calculator extends Thread {
    int total; …
Run Code Online (Sandbox Code Playgroud)

java multithreading notify wait

44
推荐指数
4
解决办法
9万
查看次数

标签 统计

java ×1

multithreading ×1

notify ×1

wait ×1