package com.tencent.java.multithread;

/**
 * sleep和wait的区别
 * @author andy
 *
 */
public class ThreadSleepAndWaitDiff {
	public static void main(String[] args) {
		
	}

}

@@ -158,15 +158,871 @@
 gs) 
-%7B%0A%09%09%0A%09%7D%0A
+throws InterruptedException %7B%0A%09%09ThreadB threadb = new ThreadB();%0A%09%09Thread thread = new Thread(threadb);%0A%09%09thread.start();%0A%09%09%0A%09%09Thread.sleep(300);%0A%09%09synchronized (threadb) %7B%0A%09%09%09System.out.println(%22get threadb monitor..%22);%0A%09%09%09try %7B%0A%09%09%09%09Thread.sleep(400);%0A%09%09%09%09%0A%09%09%09%09threadb.wait();%0A%09%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09%09// TODO Auto-generated catch block%0A%09%09%09%09e.printStackTrace();%0A%09%09%09%7D%0A%09%09%09System.out.println(%22back.%22);%0A%09%09%7D%0A%09%7D%0A%0A%7D%0A%0A%0Aclass ThreadB implements Runnable %7B%0A%0A%09@Override%0A%09public void run() %7B%0A%09%09try %7B%0A%09%09%09Thread.sleep(500);%0A%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09// TODO Auto-generated catch block%0A%09%09%09e.printStackTrace();%0A%09%09%7D%0A%09%09// TODO Auto-generated method stub%0A%09%09synchronized (this) %7B%0A%09%09%09System.out.println(%22thread:%22+Thread.currentThread().getName() + %22 running%22);%0A%09%09%09for(int i =0; i%3C100; i++) %7B%0A%09%09%09%09System.out.println(%22i:%22+i);%0A%09%09%09%7D%0A%09%09%09notify();%0A%09%09%7D%0A%09%09%0A%09%7D%0A%09
 %0A%7D%0A

add sleep and wait diff demo