少年阿宾

那些青春的岁月

  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 阅读(1559) 评论(0)  编辑  收藏 所属分类: JavaMultithread

只有注册用户登录后才能发表评论。


网站导航: