少年阿賓

          那些青春的歲月

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

          package com.abin.lee.servlet.mythread.runnable;

          import java.util.concurrent.atomic.AtomicInteger;

          public class SumThread implements Runnable{
           private  AtomicInteger num=new AtomicInteger(0);
           public void run(){
            while(num.get()<100){
             try {
              Thread.sleep(100);
             } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
             }
             if(num.get()==40){
              Thread thread2=new Thread(this,"thread2");
              thread2.start();
             }
             System.out.println(Thread.currentThread().getName()+":"+num.getAndIncrement());
            }
           }
           
          }












          package com.abin.lee.servlet.mythread.runnable;

          public class SumThreadTest {
           public static void main(String[] args) {
            SumThread ru=new SumThread();
            Thread thread1=new Thread(ru,"thread1");
            thread1.start();
           }
          }

          posted on 2012-11-05 22:40 abin 閱讀(1571) 評論(0)  編輯  收藏 所屬分類: JavaMultithread
          主站蜘蛛池模板: 吉安县| 井陉县| 平江县| 湘乡市| 乐山市| 三江| 海丰县| 堆龙德庆县| 成都市| 满城县| 长丰县| 上栗县| 萍乡市| 安庆市| 盱眙县| 顺昌县| 开原市| 沁源县| 肃宁县| 拜城县| 黎平县| 铜鼓县| 孟连| 册亨县| 襄垣县| 浦县| 新巴尔虎左旗| 和龙市| 皋兰县| 阿拉善左旗| 临洮县| 同江市| 南陵县| 余江县| 荣昌县| 贞丰县| 凌云县| 陆河县| 邻水| 姚安县| 扶绥县|