Ticket 3-implements Runnable

Source: Internet
Author: User

1  PackageXiancheng;2 3  Public classTest5Implementsrunnable{4 5     Static intpiaos=10;6      Public voidRun ()7     {8         //Sell Tickets9          while(true)Ten         { One             synchronized("") A             { -             if(piaos>=0) -             { the             Try { -Thread.Sleep (1000); -             }  -             Catch(interruptedexception e) { +                 //TODO Auto-generated catch block - e.printstacktrace (); +             } A              at             //System.out.println (Thread.CurrentThread (). GetName () + "number of votes left:" +piaos); - //             -piaos--; -              -System.out.println ( This. GetName () + "number of votes left:" +Piaos); -                  in             } -             Else to             { +System.out.println ("End of Ticket"); -                 //Break ; the             } *         } $         }Panax Notoginseng          -     } the      +     PrivateString GetName () { A         //TODO Auto-generated method stubs the         return NULL; +     } -  $      Public Static voidMain (string[] args) { $         //TODO Auto-generated method stubs -Test4 p4=NewTest4 (); -          theThread w1=NewThread (P4, "Ticket window One"); -Thread w2=NewThread (P4, "ticket window Two");WuyiThread w3=NewThread (P4, "ticket window three"); the W1.start (); - W2.start (); Wu W3.start (); -                  About  $     } -  -}

Ticket 3-implements Runnable

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.