I have recently used ScheduledExecutorService
and I am using the Executors.newScheduledThreadPool()
method. I am confused at the way it is working. I have created a program which executes every 5 sec delay and print a statement. But as per the API is concerned the Executors.newScheduledThreadPool()
is used to create threads. So in my example I am using below code
public class TestExecuterService {
public static void main(String[] args) {
ScheduledExecutorService ses = Executors.newScheduledThreadPool(0);
ses.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
System.out.println("Print every interval");
}
}, 0, 5, TimeUnit.SECONDS); // execute every x seconds
}
}
Here I have used ScheduledExecutorService ses = Executors.newScheduledThreadPool(0);
So I am assigning 0 to the thread pool. But the program is functioning the same when I assign 10 to the thread pool i.e Executors.newScheduledThreadPool(10);
.
So what is the function of the Executors.newScheduledThreadPool()
method? Please execuse me if this question is silly.