public class ScheduleExecutorServiceDemo {
public static void main(String[] args) {
ScheduledExecutorService executorService = Executors
.newScheduledThreadPool(10);
//定时执行任务,每隔2秒钟执行一次
executorService.scheduleWithFixedDelay(new Runnable() {
@Override
public void run() {
System.out.println(new Date());
}
}, 0, 2, TimeUnit.SECONDS);
}
}
摘自炼数成金。