Multi-threaded practice (simple simulation of railway station multi-window simultaneous ticketing)

Source: Internet
Author: User
Tags thread class ticket

    • Simultaneous ticketing at the train station ticketing window

 Public classXianchenglianxi { Public Static voidMain (String arg[]) {LongBegin =System.currenttimemillis (); MyThread myth_1=NewMyThread ("1");//To create a thread objectMyThread myth_2 =NewMyThread ("2"); MyThread Myth_3=NewMyThread ("3"); MyThread Myth_4=NewMyThread ("4"); MyThread myth_5=NewMyThread ("5"); Myth_1.setpriority (5);//Set Thread Priority 1 minimum 10 maximumMyth_2.setpriority (6); Myth_3.setpriority (10); Myth_4.setpriority (1); Myth_5.setpriority (8);                Myth_1.start (); //Start ThreadMyth_2.start ();        Myth_3.start ();        Myth_4.start ();    Myth_5.start (); }}classMyThreadextendsThread {//inherits the thread class in order to call its Run methodString name; intTicket = 5;//Total votes     PublicMyThread (String name) { This. Name =name; }     Public voidRun () {//method Overrides         for(inti = Ticket;i >= 0;i--){            if(I > 0) {System.out.println ("Window:" +name+ "ticket success" + "\ T" + "excess ticket" +i); }            Else{System.out.println ("Window:" +name+ "ticket success \ t" +i+ "\ t window close"); }        }            }}

Multi-threaded practice (simple simulation of railway station multi-window simultaneous ticketing)

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.