This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Sam Yim
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1951
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sam Yim
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info.

The TimeUnit for intervalTimeUnit=MILLISECONDS and durationTimeUnit=SECONDS
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic