Package Chapter III. Thread Blocking tool locksupport;
Import Java.util.concurrent.locks.LockSupport;
/**
* Created by Zzq on 2018/2/2.
*/
public class Locksupportdemo {
public static Object U = new Object ();
static Changeobjectthread T1 = new Changeobjectthread ("T1");
static Changeobjectthread t2 = new Changeobjectthread ("T2");
public static class Changeobjectthread extends Thread {
Public Changeobjectthread (String name) {
Super.setname (name);
}
public void Run () {
Synchronized (u) {
try {
Thread.Sleep (3000);
} catch (Interruptedexception e) {
E.printstacktrace ();
}
System.out.println ("in" + GetName ());
Locksupport.park ();
System.out.println ("Out" + getName ());
}
}
}
public static void Main (String args[]) throws Interruptedexception {
T1.start ();
Thread.Sleep (3000);
T2.start ();
Locksupport.unpark (t1);
Locksupport.unpark (T2);
T1.join ();
T2.join ();
}
}
3.1.7 Thread blocking Tool class: Locksupport