少年阿賓

          那些青春的歲月

            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 閱讀(1574) 評論(0)  編輯  收藏 所屬分類: JavaMultithread
          主站蜘蛛池模板: 西乡县| 河北区| 博白县| 阳春市| 建始县| 云阳县| 定襄县| 思南县| 胶南市| 内丘县| 荥阳市| 榆中县| 定襄县| 扬中市| 波密县| 嘉义市| 隆林| 昌邑市| 美姑县| 商水县| 东台市| 阜康市| 拉萨市| 桐乡市| 扎兰屯市| 东城区| 奇台县| 安多县| 焦作市| 建德市| 宁强县| 宜城市| 景东| 桃江县| 叶城县| 三明市| 临湘市| 德钦县| 府谷县| 甘孜| 靖州|