Victor wrote:
Hello,
I am using MINA 2.0 M6;
just wonder if there any way to use LinkedBlockingQueue of limited
size with OrderedThreadPoolExecutor like in standard
ThreadPoolExecutor (I mean workQueue)?
Even though OrderedThreadPoolExecutor extends ThreadPoolExecutor,
seems it ignores the parent's workQueue (I tried to pass a queue to
the parent's constructor).
My goal is to limit the number of threads in OrderedThreadPoolExecutor
in critical situations (under high load), otherwise new threads are
created constantly and I get OutOfMemory. So I think I could configure
a small "corePoolSize" and a big "workQueue" to minimize CPU usage and
context switching.
It's strange, because we have a OrderedThreadPoolExecutor(int
maximumPoolSize) constructor, which can be used to limit the pool thread :
public OrderedThreadPoolExecutor(int maximumPoolSize) {
this(DEFAULT_INITIAL_THREAD_POOL_SIZE, maximumPoolSize,
DEFAULT_KEEP_ALIVE, TimeUnit.SECONDS,
Executors.defaultThreadFactory(), null);
}
public OrderedThreadPoolExecutor(
int corePoolSize, int maximumPoolSize,
long keepAliveTime, TimeUnit unit,
ThreadFactory threadFactory, IoEventQueueHandler eventQueueHandler) {
super(DEFAULT_INITIAL_THREAD_POOL_SIZE, 1, keepAliveTime, unit,
new SynchronousQueue<Runnable>(), threadFactory, new AbortPolicy());
if (corePoolSize < DEFAULT_INITIAL_THREAD_POOL_SIZE) {
throw new IllegalArgumentException("corePoolSize: " + corePoolSize);
}
if ((maximumPoolSize == 0) || (maximumPoolSize < corePoolSize)) {
throw new IllegalArgumentException("maximumPoolSize: " + maximumPoolSize);
}
// Now, we can setup the pool sizes
super.setCorePoolSize( corePoolSize );
super.setMaximumPoolSize( maximumPoolSize );
So unless there is a bad bug in the ThreadPoolExecutor class, I don't
see how the number of created thread can go above the limit...
--
--
cordialement, regards,
Emmanuel Le'charny
www.iktek.com
directory.apache.org