日期:2014-05-20 浏览次数:21081 次
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
public class T {
private static int count=0;
/**
* @param args
*/
public static void main(String[] args) {
class MyTimerTask extends TimerTask{
@Override
public void run() {
count=(count+1)%2;
System.out.println(Thread.currentThread().getName()+" count:"+count);
new Timer().schedule(new MyTimerTask(), 0+count*2);
}
}
TimerTask task=new MyTimerTask();
System.out.println("开始");
new Timer().schedule(task, 3000);
while(true){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(" "+Thread.currentThread().getName()+" "+new Date().getSeconds());
}
}
}