[concurrency-interest] ScheduledThreadPoolExecutor and stalled jobs

David Holmes dcholmes at optusnet.com.au
Tue Nov 14 23:00:54 EST 2006


Just had a thought ...

ScheduledThreadPoolExecutor operates by dequeing a task and executing it,
then requeuing afterwards. This means that a task is never running
concurrently with itself if it executes beyond its next release time.

A different model of periodic task execution would leave the task in the
queue so that every period a new execution of it commences, even if the
previous one had not completed.

If you expected this second model then that is not what you get with
ScheduledThreadPoolExecutor.

Hope that helps.

David Holmes

> -----Original Message-----
> From: concurrency-interest-bounces at cs.oswego.edu
> [mailto:concurrency-interest-bounces at cs.oswego.edu]On Behalf Of Harsha
> Nagesh
> Sent: Wednesday, 15 November 2006 11:46 AM
> To: concurrency-interest at cs.oswego.edu
> Subject: [concurrency-interest] ScheduledThreadPoolExecutor and stalled
> jobs
>
>
> Hi,
>
>      I am trying to use ScheduledThreadPoolExecutor to schedule a bunch of
> jobs, each of which should be scheduled every minute. I am
> running this on win
> XP and using a poolsize = 20 (threads). However, what I see is
> that out of the
> 100 or so jobs that have been added to the scheduler, there is a
> subset of them
> (more than 20%) which seem to be scheduled once and never again
> after the first
> time. I am not sure how to go about debugging this issue. Any
> pointers will be
> greatly appreciated. Here is the skeleton of code that shows the
> way I am using
> the scheduler and I am not sure if this is the best way to
> achieve my objective
>
> int poolSize = 20;
> long period = 60; //1 minute
> long delay = 60; //1 minute
> TimeUnit timeUnit = TimeUnit.SECONDS;
>
> ScheduledThreadPoolExecutor pool = new
>           ScheduledThreadPoolExecutor(poolSize);
> for(int i = 0; i < 100; i++){
>    MyTask task = new MyTask();
>    pool.scheduleAtFixedRate(task,0,period,timeUnit);
> }
>
> I also tried to use
>
> pool.scheduleWithFixedDelay(task,0,delay,timeUnit);
>
> instead of the fixedRate scheduling, but I found the same
> behavior and many of
> my jobs were stuck and not executed after the first run.
>
> Any ideas ?
>
> Thanks,
> Harsha
>
>
>
>
> __________________________________________________________________
> __________________
> Yahoo! Music Unlimited
> Access over 1 million songs.
> http://music.yahoo.com/unlimited
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest



More information about the Concurrency-interest mailing list