- ScheduledExecutorService executorService = Executors.newScheduledThreadPool(3);
- executorService.scheduleWithFixedDelay( new Runnable(){
- @Override
- public void run() {
- System.out.println("scheduled:" +newDate() + " " + Thread.currentThread().getId());
- try {
- Thread.sleep(1000*3);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- }, 1000 * 5, 1000*1, TimeUnit.MILLISECONDS );
来源: http://www.bubuko.com/infodetail-1995063.html