Bzu-java (ix)

Source: Internet
Author: User

public class Test {public static void main (string[] args) {Tunnel tul = new tunnel ();        Thread P1 = new Thread (Tul, "P1");        Thread P2 = new Thread (Tul, "P2");        Thread p3 = new Thread (Tul, "P3");        Thread P4 = new Thread (Tul, "P4");        Thread P5 = new Thread (Tul, "P5");        Thread P6 = new Thread (Tul, "P6");        Thread P7 = new Thread (Tul, "P7");        Thread P8 = new Thread (Tul, "P8");        Thread p9 = new Thread (Tul, "p9");        Thread P10 = new Thread (Tul, "P10");        P1.start ();        P2.start ();        P3.start ();        P4.start ();        P5.start ();        P6.start ();        P7.start ();        P8.start ();        P9.start ();    P10.start ();    }}class Tunnel implements runnable{private int crossednum = 0;    Override public void Run () {cross ();        } public synchronized void Cross () {try {thread.sleep (2000);        } catch (Interruptedexception e) {e.printstacktrace ();        }crossednum++; System.out.println (Thread.CurrentThread (). GetName () + "have crossed the tunnel!"            + "This is" +crossednum+ "th"); }}

Bzu-java (ix)

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.