About the diffrence of wait timed_wait and block in Java

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.