I have used ScheduledThreadPoolExecutor in following example
Now this is what javadocs says about ScheduledThreadPoolExecutor
[javadoc]public ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
TimeUnit unit)Description copied from interface: ScheduledExecutorService
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor.
scheduleAtFixedRate in interface ScheduledExecutorService
command - the task to execute.
initialDelay - the time to delay first execution.
period - the period between successive executions.
unit - the time unit of the initialDelay and period parameters
a Future representing pending completion of the task, and whose get() method will throw an exception upon cancellation.[/javadoc]
So according to javadocs for every millisecond a thread should be invoked and increment the count and then go for sleep.
But this is what I get in console:
1265023803311 pool-1-thread-1 ---> 1
1265023813311 pool-1-thread-1 ---> 2
1265023823311 pool-1-thread-1 ---> 3
1265023833311 pool-1-thread-1 ---> 4
1265023843311 pool-1-thread-1 ---> 5
My question is why another thread in the pool is not getting started. As you can see from time diference , I have to wait for thread 1 to be completed, then only the task is done again ? My expectation given the delay in sleep all 5 threads would be getting started.
Please suggest me if I am correct and how to get second thread started ?