The ScheduledExcecutorService
is an interface. That means it dictates what methods the service must have but doesn't do anything else... cause in java... that's what interfaces do... boss classes around... it's the java way.
So we need a class that implements the interface... and there just happens to be one in the java.util.concurrent
package. We can create it using the Executor
utility class that has a factory method to create the scheduler. That factory method is newScheduledThreadPool(int)
the parameter (an int) --> how many threads you want to start.
The threads themselves are autonomous... i.e. they run in their own space. That means you need to shut them down or it will keep the JVM alive. Use the shutdown()
method to accomplish this task.