[concurrency-interest] missed deadlines.

Joe Bowbeer joe.bowbeer at gmail.com
Thu Jul 6 15:27:33 EDT 2006


On 7/6/06, Peter Veentjer <alarmnummer at gmail.com> wrote:
> I have a question regarding missed deadlines and java.util.Timer and
> java.util.concurrent.ScheduledThreadPoolExecutor.
>
> I'm wondering why there is no functionality for dealing with missed
> deadlines. Within a Timer you have one thread, if a job takes a long
> time, the other tasks are 'queued' untill the long-job has finished.
> When that job finishes, all other queued-jobs are run and I think this
> could lead to some serious issues. I can image you want to have some
> control like:
> -execute it
> -drop it
> -do something else like sending a message.
>
> The same goes for the ScheduledThreadPoolExecutor. If a job takes a
> long time and a different job needs to be scheduled, a free thread is
> used (if one is available). If no free thread is available, you get
> the same problems as with the Timer.
>
> Another think I'm wondering about is the fixed size of the threadpool
> of the scheduledthreadpoolexecutor. I can image it would be usefull
> that a threadpool increases if there are no available threads to
> execute a scheduled task and if those 'extra' threads aren't used for
> some time, they could be discarded. Am I missing something?
>
> Peter


I understand your main point is that the scheduled executor doesn't
automatically create threads in order to satisfy/meet the schedule,
and I have nothing to offer :-)

For dropping tasks when the deadline has been missed, I want to point
out that there are helper methods to help tasks decide that.

TimerTask has scheduledExecutionTime

   public void run() {
       if (System.currentTimeMillis() - scheduledExecutionTime() >=
           MAX_TARDINESS)
               return;  // Too late; skip this execution.
       // Perform the task
   }

And ScheduledFuture has getDelay.  (But, on closer inspection, I think
it may be tricky for a scheduled runnable or callable "task" to call
this method, since a ScheduledFuture is created for the task by the
ScheduledExecutorService when the task is submitted.)

--Joe


More information about the Concurrency-interest mailing list