tout dans la question. je n'arrive pas à faire la différence entre ces deux méthodes:
scheduleAtFixedRate (Runnable, long initialDelay, long period, TimeUnit timeunit)
scheduleWithFixedDelay (Runnable, long initialDelay, long period, TimeUnit timeunit)
exemple:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(2); System.out.println("Current Time = " + new Date()); for (int i = 0; i < 3; i++) { Thread.sleep(1000); Runnable runnable = () -> { System.out.println(Thread.currentThread().getName() + " Start. Time = " + new Date()); processCommand();//Thread.sleep(5000); System.out.println(Thread.currentThread().getName() + " End. Time = " + new Date()); }; scheduledThreadPool.scheduleWithFixedDelay(runnable, 1,2, TimeUnit.SECONDS); }
Partager