Reputation: 113
If i schedule multiple tasks for ScheduledExecutorService , but i have made sure that there can be only thread to execute all the tasks, would each task be executed sequentially?
For eg: what happens in below scenario
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleWithFixedDelay(new Runnable{void run(){....}}, 6000,6000,TimeUnit.MILLISECONDS);
scheduler.scheduleWithFixedDelay(new Runnable{void run(){....}}, 6000,6000,TimeUnit.MILLISECONDS);
Upvotes: 3
Views: 2541
Reputation: 12985
From the javadoc:
Creates an Executor that uses a single worker thread operating off an unbounded queue. (Note however that if this single thread terminates due to a failure during execution prior to shutdown, a new one will take its place if needed to execute subsequent tasks.) Tasks are guaranteed to execute sequentially, and no more than one task will be active at any given time. Unlike the otherwise equivalent newFixedThreadPool(1) the returned executor is guaranteed not to be reconfigurable to use additional threads.
Upvotes: 4