https://issues.apache.org/bugzilla/show_bug.cgi?id=49159
--- Comment #8 from sylvain.laur...@gmail.com 2010-09-25 18:42:53 EDT ---
Created an attachment (id=26074)
 --> (https://issues.apache.org/bugzilla/attachment.cgi?id=26074)
proposed patch to renew threads one by one with a delay

I explored your idea and managed to force threads to "kill themselves" after a
context is stopped.
Here are the main points of my new patch :

- I save the last time a context is stopped in a static variable of
StandardContext (this could be improved to record it somewhere at the Service
or Engine level, in a instance variable)
- The "suicide" is done in ThreadPoolExecutor.afterExecute(), in case the
thread was created before the last context was stopped.
- the rate at which threads are renewed is throttled to avoid renewing all
threads at the same time (otherwise it would have been the same as my initial
proposal to renew the whole pool).
- I had to make TaskQueue extend ArrayBlockingQueue instead of
LinkedBlockingQueue because the latter does not propose to have a "fair"
policy. Fairness is required so that every thread of the pool is given the
opportunity to be killed.
- Unlike LinkedBlockingQueue, ArrayBlockingQueue requires a reasonable size
(not Integer.MAX_VALUE). I set it to 100 by default (configurable with the
maxQueueSize property at the Connector or Executor level)

I'm quite happy with this patch except the fairness requirement :
- The javadocs of ArrayBlockingQueue say that it may decrease performance, but
I don't how much
- Since each thread of the pool is used in turn, we might lose some caching
effects
- and it also prevents the size of the pool to be decreased in case of low
activity : without fairness, some Thread could timeout waiting for an element
from the queue while other threads could serve new requests. Eventually the
pool could decide to decrease it size.

What do you think ? If we don't use a fair queue, we do not have a
deterministic behavior and some thread might still trigger a memory leak...

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to