关于多线程的wait和notify产生的问题。
class Maintest { public static void main(String args[]) throws Exception { ThreadDemo thr = new ThreadDemo(); thr.start(); for (int i = 1; i < 1000; i++) { synchronized (Maintest.class) { //Maintest.class是什么意思,非常不明白 System.out.println("main: " + i); Maintest.class.notify(); //这个与下边怎么联系? Maintest.class.wait(); } } }}class ThreadDemo extends Thread { public void run() { for (int i = 1; i < 1000; i++) { try { synchronized (Maintest.class) { System.out.println(this.getName() + ":" + i); Maintest.class.notify(); Maintest.class.wait(); } } catch (InterruptedException e) { e.printStackTrace(); } } }}synchronized (Maintest.class) { System.out.println("main: " + i); Maintest.class.notify(); }
[解决办法]
这个例子比较有才。
[解决办法]
[解决办法]
路过
[解决办法]