You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Sylvain Laurent <sy...@m4x.org> on 2010/05/06 23:20:53 UTC
Re: Need advice to notify StandardExecutor when a webapp is stopped
I finally proposed a patch for trunk in https://issues.apache.org/bugzilla/show_bug.cgi?id=49159 for this. Thanks for reviewing it...
Sylvain
On 30 avr. 2010, at 18:27, Sylvain Laurent wrote:
>
> On 30 avr. 2010, at 00:01, Pid wrote:
>>
>> Are you saying that you want to stop processing requests each time a
>> webapp gets restarted, or that the thread pool is refreshed by
>> sequentially killing each thread and recreating it?
>
> Something in between : I create a new pool with the same characteristics as the current one, make it the current pool so that new requests are served by the new pool, then cleanly shut the old pool down. When calling ThreadPoolExecutor.shutdown(), it gracefully terminates all threads in the pool after its associated TaskQueue is empty : Idle threads stop immediately (and not sequentially), busy threads continue processing their current request. If the TaskQueue is not empty, it means that there are no idle threads, and so busy threads will continue processing tasks in the queue until it becomes empty.
>
> The renewThreads looks like (in StandardThreadExecutor) :
>
> public void renewThreads() {
> ThreadPoolExecutor oldExecutor;
> synchronized (executorLock) { // to avoid renewing threads concurrently
> oldExecutor = executor;
> ThreadPoolExecutor newExecutor=new ThreadPoolExecutor(getMinSpareThreads(),
> getMaxThreads(), maxIdleTime, TimeUnit.MILLISECONDS,
> taskqueue, oldExecutor.getThreadFactory());
>
> executor = newExecutor;
> taskqueue.setParent(executor);
> }
>
> oldExecutor.shutdown();
> //we don't wait for termination of the old pool, threads will terminate when their work is done
> }
>
> I marked StandardThreadExecutor.executor and TaskQueue.parent as volatile to propagate the change of executor instance to other threads without synchronizing threads.
>
> An improvement I can do is to pre-start some "core" threads in the new pool before making it active. It would reduce the performance impact on the next few requests.
>
> Sylvain
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org
RE: Need advice to notify StandardExecutor when a webapp is stopped
Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Sylvain Laurent [mailto:sylvain.laurent@gmail.com]
> On Behalf Of Sylvain Laurent
> Subject: Re: Need advice to notify StandardExecutor when a
> webapp is stopped
>
> An improvement I can do is to pre-start some "core" threads in the
> new pool before making it active. It would reduce the performance
> impact on the next few requests.
Or have another Executor sitting around with some threads already active, so all you have to do is set the reference to the pending Executor, then create another backup Executor outside of the synchronized block for the next time. Could also make the behavior configurable, in case the purists complain about having extra, idle threads taking up heap space.
- Chuck
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org