Multi-Threading vs. static proxies

Source: Internet
Author: User

Package thread;//easy to share resources public class multi-threading with proxy {public static void main (string[] args) {//Real role Web12306 web=new Web12306 ();//Generation Manager thread T1=new Thread (web, "xiaoming"); Thread t2=new thread (web, "Hong"); Thread t3=new thread (web, "Huahua"); T1.start (); T2.start (); T3.start ();}} Class Web12306 implements Runnable{private int num=50;//remaining 50 tickets @overridepublic void run () {//TODO auto-generated Method St Ubwhile (True) {if (num<=0) {break;//jumps out of the Loop}system.out.println (Thread.CurrentThread (). GetName () + "grabbed" +num--);}}

Hong has robbed 50.
Hong has robbed 48.
Hong has robbed 47.
Hong has robbed 46.
Hong has robbed 45.
Hong has robbed 44.
Hong has robbed 43.
Hong has robbed 42.
Hong has robbed 41.
Hong has robbed 40.
Hong has robbed 39.
Hong has robbed 37.
Hong has robbed 36.
Hong has robbed 35.
Hong has robbed 34.
Hong has robbed 33.
Hong has robbed 32.
Hong has robbed 31.
Xiaoming grabbed 49.
Hong has robbed 30.
Huahua grabbed 38.
Hong has robbed 28.
Xiaoming grabbed 29.
Hong has robbed 26.
Huahua grabbed 27.
Hong has robbed 24.
Xiaoming grabbed 25.
Xiaoming grabbed 21.
Xiaoming grabbed 20.
Xiaoming grabbed 19.
Xiaoming grabbed 18.
Hong has robbed 22.
Hong has robbed 16.
Huahua grabbed 23.
Hong has robbed 15.
Xiaoming grabbed 17.
Hong has robbed 13.
Huahua grabbed 14.
Hong has robbed 11.
Xiaoming grabbed 12.
Hong has robbed 9.
Huahua grabbed 10.
Hong has robbed 7.
Xiaoming grabbed 8.
Hong has robbed 5.
Huahua grabbed 6.
Hong has robbed 3.
Xiaoming grabbed 4.
Hong has robbed 1.
Huahua grabbed 2.

Multi-Threading vs. static proxies

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.