I am creating a pool of 10 threads Each thread runs for 3 seconds I set the startup period of each task to 0.5 seconds
The question is, if the pool consists of 10 threads, and the startup period is 0.5 seconds, why does it take 3 seconds from the first thread to start the second one? After all, 10 threads should start in 0.5 seconds at once, and so on.
If I were to use newSingleThreadScheduledExecutor it would be understandable, but I'm using newScheduledThreadPool with 10 threads.
public class Main17 {
public static void main(String[] args) {
ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(10);
Runnable r = ()-> {
System.out.println("hello "+System.currentTimeMillis());
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
};
scheduledExecutorService.scheduleAtFixedRate(r,0, 500, TimeUnit.MILLISECONDS);
}
}
result
hello 1646991199804
hello 1646991202816 // Interval greater than 0.5 seconds
hello 1646991205831
hello 1646991208840
hello 1646991211850