ExecutorService_ScheduledThreadP
2017-01-03 本文已影响0人
perfect_jimmy
public class ScheduledThreadPool {
public static void main(String[] args){
ScheduledExecutorService schedulePool = Executors.newScheduledThreadPool(1);
//3秒后执行
schedulePool.schedule(new Runnable(){
@Override
public void run() {
System.out.println("爆炸--"+System.currentTimeMillis());
}
},3,TimeUnit.SECONDS);
//3秒后执行且每隔1秒执行
schedulePool.scheduleAtFixedRate(new Runnable(){
@Override
public void run() {
System.out.println("爆炸=="+System.currentTimeMillis());
}
},3,1,TimeUnit.SECONDS);
}
}
ScheduledThreadPool可以定时的或延时的执行任务
爆炸--1483421657158
爆炸==1483421657158
爆炸==1483421658159
爆炸==1483421659159
爆炸==1483421660159
爆炸==1483421661159
爆炸==1483421662159
爆炸==1483421663159