日期:2014-05-20 浏览次数:20776 次
package com.ssj.test; public class NotifySynch { private Object lock = new Object(); class ThreadA extends Thread{ @Override public void run() { for(int i = 0 ; i < 6 ; i++){ System.out.println("ThreadA"); } synchronized(lock){ lock.notifyAll(); } } } class ThreadB extends Thread{ @Override public void run() { synchronized(lock){ try { lock.wait(); } catch (InterruptedException e) { } } for(int i = 0 ; i < 6 ; i++){ System.out.println("ThreadB"); } } } public void testRun(){ new ThreadB().start(); new ThreadA().start(); } public static void main(String[] args) { new NotifySynch().testRun(); } }