package com.chain.core.test; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import com.chain.core.test.Test.Wait; public class Test2 { /** * <Method Simple Description> * @param args * @author Administrator * @see */ public static void main(String[] args) { TT tt = new TT(); tt.start(); try { Thread.sleep(8000); } catch (InterruptedException e) { e.printStackTrace(); } System.out.println("rrr----->" + tt.isInterrupted()); tt.tt3.r(); } public static class TT extends Thread { // public TT2 tt2 = new TT2(); public TT3 tt3 = new TT3(); public void run() { // tt2.setDaemon(true); // tt2.start(); // int i = 1; // p(); // while (i>0) { // System.out.println("tt------>" + i); // try { // Thread.sleep(1000); // } catch (InterruptedException e) { // System.out.println("tt------>III"); // e.printStackTrace(); // } // i++; // } tt3.run(); } // public void p() { // synchronized (tt2) { // try { // tt2.wait(); // } catch (InterruptedException e1) { // e1.printStackTrace(); // } // } // } } public static class TT2 extends Thread { public void run() { int i = 0; while (true) { System.out.println("tt2------>" + i); try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("tt2------>III"); e.printStackTrace(); } i++; } } } public static class TT3 { private Object o = new Object(); public void run() { int i = 0; while (true) { System.out.println("tt3------>" + i); if (i == 5) { synchronized (o) { try { o.wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } try { Thread.sleep(1000); } catch (InterruptedException e) { System.out.println("tt2------>III"); e.printStackTrace(); } i++; } } public void r() { synchronized (o) { o.notifyAll(); } } } }