码迷,mamicode.com
首页 > 编程语言 > 详细

java多线程编程(3)买票

时间:2014-07-19 09:35:31      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   java   color   os   

1,买票非同步版本

http://www.cnblogs.com/anbylau2130/archive/2013/04/17/3025347.html很详细

bubuko.com,布布扣
 1 public class 多线程2 {
 2 
 3     /**
 4      * @param args
 5      */
 6     public static void main(String[] args) {
 7         // TODO Auto-generated method stub
 8         Runnable r=new mythread();
 9         Thread t1=new Thread(r);
10         Thread t2=new Thread(r);
11         t1.start();
12         t2.start();
13 
14     }
15 
16 }
17 class  mythread implements Runnable
18 {
19     private int  num=100;
20   public void run()
21   {
22      while(true)
23      {
24          if(num>0){
25              try {
26                 Thread.sleep(1000);
27             } catch (InterruptedException e) {
28                 // TODO Auto-generated catch block
29                 e.printStackTrace();
30             }
31              
32              
33              System.out.println(Thread.currentThread().getName()+"剩下"+num--);}
34          else break;
35          
36      }
37       
38   }
39     
40 
41 }
View Code

java多线程编程(3)买票,布布扣,bubuko.com

java多线程编程(3)买票

标签:style   blog   http   java   color   os   

原文地址:http://www.cnblogs.com/hansongjiang/p/3854250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!