unbounded-queue-thread-pool is not releasing idle threads

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform
    • 6.x

Issue

According to this document, “unbounded-queue-thread-pool” is defined for http executor. However, it looks like the idle threads are not released even after keepalive-time.

The current-thread-count are never decreased.

[standalone@localhost:9999 /] /subsystem=threads/unbounded-queue-thread-pool=uq-thread-pool:read-resource(include-runtime=true)
{
    "outcome" => "success",
    "result" => {
        "active-count" => 3,
        "completed-task-count" => 629L,
        "current-thread-count" => 632,
        "keepalive-time" => {
            "time" => 30L,
            "unit" => "SECONDS"
        },
        "largest-thread-count" => 632,
        "max-threads" => 1000,
        "name" => "uq-thread-pool",
        "queue-size" => 0,
        "rejected-count" => 0,
        "task-count" => 632L,
        "thread-factory" => "http-connector-factory"
    }
}

Resolution

  • At the moment, there is no workaround. Other executors can be used to reclaim idle threads instead (such as bounded-queue-thread-pool), but typically there's no benefit to reclaim idle threads.

Root Cause

"When a new task is submitted in method execute(java.lang.Runnable), and fewer than corePoolSize threads are running, a new thread is created to handle the request, even if other worker threads are idle. If there are more than corePoolSize but less than maximumPoolSize threads running, a new thread will be created only if the queue is full.
...
If the pool currently has more than corePoolSize threads, excess threads will be terminated if they have been idle for more than the keepAliveTime (see getKeepAliveTime(java.util.concurrent.TimeUnit))."
  • So an executor creates up to core threads first, then queues, then expands beyond core threads to max threads. If you have an unbounded queue, then this effectively means that core threads is equal to max threads. Since all threads are core threads, this means each accepted connection is going to result in a new core thread until the max size is reached. And since they're all core threads, none of them will be timed out.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Close

Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.