aspose file tools*
The moose likes Threads and Synchronization and the fly likes Is the ScheduledExecutorService.schedule() dependent on core pool size? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "Is the ScheduledExecutorService.schedule() dependent on core pool size?" Watch "Is the ScheduledExecutorService.schedule() dependent on core pool size?" New topic
Author

Is the ScheduledExecutorService.schedule() dependent on core pool size?

Sam Yim
Greenhorn

Joined: Jul 25, 2009
Posts: 17
Is the ScheduledExecutorService.schedule() dependent on the core pool size?

The list of Runnables I have is equivalent to the core pool size.
For each scheduled Runnable, I'm creating a one-time scheduled task to to cancel the "scheduleAtFixedRate-task".

So in the sample code below, for each "scheduleAtFixedRate-task" I create a "one-time scheduled task" is created to cancel the "scheduleAtFixedRate-task" after the specify duration (delay).

The code as-is (below), seems to take quite longer than expected to canel.

When I change the delcaration to specified the (corePoolSize*2) seems to be running better (cancelling seems almost on time to the specified duration).

This leads me to think the call to ScheduledExecutorService.schedule() is restricted to what the corePoolSize is defined.


Jelle Klap
Bartender

Joined: Mar 10, 2008
Posts: 1760
    
    7

Both schedule() and scheduleAtfixedRate() use the same thread pool, but since you're creating a ScheduledExecutorService using the Executors class you're not (practically) bound to a maximum pool size. So even if the number of Runnables you scheduleAtFixedRate() is equal to the core pool size, that shouldn't prevent the Runnable cancellation tasks you schedule() from executing "on time", because new Threads are created as needed. I put "on time" in quotes, because their Threads still do require CPU time, which they might not get if the Runnables they're supposed to cancel are spin waiting, for instance.
What sort of granularity are we talking about by the way, TimeUnit wise?


Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Sam Yim
Greenhorn

Joined: Jul 25, 2009
Posts: 17
Thanks for the info.

The TimeUnit for intervalTimeUnit=MILLISECONDS and durationTimeUnit=SECONDS
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is the ScheduledExecutorService.schedule() dependent on core pool size?