scheduledthreadpoolexecutor threadsafe?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

scheduledthreadpoolexecutor threadsafe?

Peter Veentjer - Anchor Men
I have a question about the thread safety of the
ScheduledThreadPoolExecutor.

eg:

 private void delayedExecute(Runnable command) {
        if (isShutdown()) {
            reject(command);
            return;
        }
        // Prestart a thread if necessary. We cannot prestart it
        // running the task because the task (probably) shouldn't be
        // run yet, so thread will just idle until delay elapses.
        if (getPoolSize() < getCorePoolSize())
            prestartCoreThread();
           
        super.getQueue().add(command);
    }

It could happen that a command is added to the Queue altough the
ExecutorService has just been shutdown. This task will never be
executed. Shouldn`t it be better if the ScheduledThreadPoolExecutor
received a Lock from the ThreadPoolExecutor to make this an atomic
action?

The reason I`m asking this question is that I`m also extending to
ThreadPoolExecutor to getter better control on timout behaviour of the
offering of tasks.

Met vriendelijke groet,

Peter Veentjer
Anchor Men Interactive Solutions - duidelijk in zakelijke
internetoplossingen

Praediniussingel 41
9711 AE Groningen

T: 050-3115222
F: 050-5891696
E: [hidden email]
I : www.anchormen.nl

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

RE: scheduledthreadpoolexecutor threadsafe?

Peter Veentjer - Anchor Men
 Hmm.. maybe I know the answer to my own question. The
ThreadPoolExecutor will execute all remaining tasks if it is shutdown.
So all queued tasks will be processed (unless shutdownNow is called).

-----Oorspronkelijk bericht-----
Van: [hidden email]
[mailto:[hidden email]] Namens Peter
Veentjer - Anchor Men
Verzonden: dinsdag 29 november 2005 14:40
Aan: [hidden email]
Onderwerp: [concurrency-interest] scheduledthreadpoolexecutor
threadsafe?

I have a question about the thread safety of the
ScheduledThreadPoolExecutor.

eg:

 private void delayedExecute(Runnable command) {
        if (isShutdown()) {
            reject(command);
            return;
        }
        // Prestart a thread if necessary. We cannot prestart it
        // running the task because the task (probably) shouldn't be
        // run yet, so thread will just idle until delay elapses.
        if (getPoolSize() < getCorePoolSize())
            prestartCoreThread();
           
        super.getQueue().add(command);
    }

It could happen that a command is added to the Queue altough the
ExecutorService has just been shutdown. This task will never be
executed. Shouldn`t it be better if the ScheduledThreadPoolExecutor
received a Lock from the ThreadPoolExecutor to make this an atomic
action?

The reason I`m asking this question is that I`m also extending to
ThreadPoolExecutor to getter better control on timout behaviour of the
offering of tasks.

Met vriendelijke groet,

Peter Veentjer
Anchor Men Interactive Solutions - duidelijk in zakelijke
internetoplossingen

Praediniussingel 41
9711 AE Groningen

T: 050-3115222
F: 050-5891696
E: [hidden email]
I : www.anchormen.nl

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest