Victor wrote:
Emmanuel,

no, there is no bug with thread limit!
I am talking about workQueue - in a typical ThreadPoolExecutor you can configure a working queue of any size (limited or not) and this queue can be used to minimize the number of running threads in thread pool. Just look at javadoc in ThreadPoolExecutor class in java 6:

"
If corePoolSize or more threads are running, the Executor always prefers queuing a request rather than adding a new thread.
"

Sorry, I was focusing on your last sentence :
"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 you get OOM because the working queue is unbound : then I'm afraid this queue cannot be modified . probably worth a JIRA at this point.



Victor N


Emmanuel Lecharny wrote:
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 Lécharny
www.iktek.com
directory.apache.org


Reply via email to