Import Java.util.concurrent.locks.lock;import java.util.concurrent.locks.reentrantlock;/** * * @author daxin * */ public class Main1 {static lock lock = new Reentrantlock ();p ublic static void Main (string[] args) throws Exception {//TIM ed_waiting//Thread.Sleep (5000*5000);//----------------synchronized---------------------//Timed_waitingnew Thread (Target1, "1"). Start (); Thread.Sleep ($);//Blockednew Thread (Target1, "2"). Start ();//----------------lock------------------//Timed_ Waitingnew Thread (Target2, "3"). Start (); Thread.Sleep (+);//Waitingnew Thread (Target2, "4"). Start (); public static synchronized void get () {try {thread.sleep (*),} catch (Interruptedexception e) {//TODO Auto-gener Ated catch Blocke.printstacktrace ();} Finally {}}public static void Get2 () {try {lock.lock (); Thread.Sleep (5000 * 5000);} catch (Interruptedexception e) {//TODO auto-generated catch Blocke.printstacktrace ();} finally {Lock.unlock ()}} static Runnable Target1 = new Runnable () {@Overridepublic void Run () {//TODO auto-generated method Stubget ();}}; static Runnable Target2 = new Runnable () {@Overridepublic void Run () {//TODO auto-generated method Stubget2 ();}};}
About the diffrence of wait timed_wait and block in Java