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();
}
}