介绍
JBoss作为Java web服务器,监听并接收http请求和应答响应,采用同步阻塞IO。启线程模型如下:
Acceptor和Poller线程栈参考如下:
1 |
|
默认处理线程名为:http--0.0.0.0:8080-N
,自定义执行器时处理线程名:${executor}-threads-N
,${executor}
即executor
的name
属性值。
JBOSS7支持多种执行器(executor,线程池),参考如下图,详情可以参考${JBOSS_HOME}\docs\schema\jboss-as-threads_1_1.xsd
各种执行器配置参数如下:
executor | core-threads | queue | max-threads | keepalive-time | blocking | thread-factory |
---|---|---|---|---|---|---|
unbounded-queue-thread-pool | 无上限 | 指定 | 指定 | |||
bounded-queue-thread-pool | 指定 | 指定 | 指定 | 指定 | false | |
blocking-bounded-queue-thread-pool | 指定 | 指定 | 指定 | 指定 | true | |
queueless-thread-pool | 指定 | 指定 | false | |||
blocking-queueless-thread-pool | 指定 | 指定 | true | |||
scheduled-thread-pool | 指定 | 指定 |
在JBOSS7配置文件${JBOSS_HOME}/standalone/configuration/standalone.xml
中threads
节点下定义,默认没有定义(jboss7默认可能用的thread-factory
(因为没有过期时间,从执行来看,线程不释放 )),如:
1 |
|
thread-factory
A thread factory (implementing java.util.concurrent.ThreadFactory). The “name
” attribute is the bean name of the created thread factory. The optional “priority
” attribute may be used to specify the thread priority of created threads. The optional “group-name
” attribute specifies the name of a the thread group to create for this thread factory. The “thread-name-pattern
” is the template used to create names for threads. The following patterns may be used:
1 |
|
bounded-queue-thread-pool
A thread pool executor with a bounded queue, where threads attempting to submit tasks will not block
. Such a thread pool has a core
and maximum
size and a specified queue length
. When a task is submitted, if the number of running threads is less than the core size, a new thread is created. Otherwise, if there is room in the queue, the task is enqueued. Otherwise, if the number of running threads is less than the maximum size, a new thread is created. Otherwise, the task is handed off to the designated handoff executor, if one is specified. Otherwise, the task is discarded
.
The “name
” attribute is the bean name of the created executor. The “allow-core-timeout
” attribute specifies whether core threads may time out; if false, only threads above the core size will time out. The optional “core-threads
” element may be used to specify the core thread pool size which is smaller than the maximum pool size. The required “max-threads
” element specifies the maximum thread pool size. The required “queue-length
” element specifies the queue length. The optional “keepalive-time
” element may used to specify the amount of time that threads beyond the core pool size should be kept running when idle. The optional “thread-factory
” element specifies the bean name of a specific thread factory to use to create worker threads. The optional “handoff-executor
” element specifies an executor to delegate tasks to in the event that a task cannot be accepted.
1 |
|
疑问:设置blocking=”true”会报解析配置文件失败,Failed to parse configuration,Unexpected attribute ‘blocking’ encountered
unbounded-queue-thread-pool
A thread pool executor with an unbounded queue
. Such a thread pool has a core size and a queue with no upper bound. When a task is submitted, if the number of running threads is less than the core size, a new thread is created. Otherwise, the task is placed in queue. If too many tasks are allowed to be submitted to this type of executor, an out of memory condition may occur.
The “name
” attribute is the bean name of the created executor. The “max-threads
” attribute must be used to specify the thread pool size. The nested “keepalive-time
” element may used to specify the amount of time that pool threads should be kept running when idle; if not specified, threads will run until the executor is shut down. The “thread-factory
” element specifies the bean name of a specific thread factory to use to create worker threads.
1 |
|
blocking-bounded-queue-thread-pool
A thread pool executor with a bounded queue, where threads attempting to submit tasks may block
. Such a thread pool has a core and maximum size and a specified queue length. When a task is submitted, if the number of running threads is less than the core size, a new thread is created. Otherwise, if there is room in the queue, the task is enqueued. Otherwise, if the number of running threads is less than the maximum size, a new thread is created.Otherwise, the caller blocks until room becomes available in the queue.
The “name
” attribute is the bean name of the created executor. The “allow-core-timeout
” attribute specifies whether core threads may time out; if false, only threads above the core size will time out. The optional “core-threads
” element may be used to specify the core thread pool size which is smaller than the maximum pool size. The required “max-threads
” element specifies the maximum thread pool size. The required “queue-length
” element specifies the queue length. The optional “keepalive-time
” element may used to specify the amount of time that threads beyond the core pool size should be kept running when idle. The optional “thread-factory
” element specifies the bean name of a specific thread factory to use to create worker threads.
1 |
|
queueless-thread-pool
A thread pool executor with no queue, where threads attempting to submit tasks will not block. When a task is submitted, if the number of running threads is less than the maximum size, a new thread is created. Otherwise, the task is handed off to the designated handoff executor, if one is specified. Otherwise, the task is discarded
.
The “name
” attribute is the bean name of the created executor. The “max-threads
” attribute specifies the number of threads to use for this executor before tasks cannot be accepted anymore. The optional “keepalive-time
” is used to specify the amount of time that threads should be kept running when idle; by default threads run indefinitely. The optional “thread-factory
” element specifies the bean name of a specific thread factory to use to create worker threads. The optional “handoff-executor
” element specifies an executor to delegate tasks to in the event that a task cannot be accepted.
1 |
|
blocking-queueless-thread-pool
A thread pool executor with no queue, where threads attempting to submit tasks may block. When a task is submitted, if the number of running threads is less than the maximum size, a new thread is created. Otherwise, the caller blocks until another thread completes its task and accepts the new one.
The “name
” attribute is the bean name of the created executor. The “max-threads
” attribute specifies the number of threads to use for this executor before tasks cannot be accepted anymore. The optional “keepalive-time
” is used to specify the amount of time that threads should be kept running when idle; by default threads run indefinitely. The optional “thread-factory
” element specifies the bean name of a specific thread factory to use to create worker threads.
1 |
|
scheduled-thread-pool
A scheduled thread pool executor.
The “name
” attribute is the bean name of the created executor. The “thread-factory
” attribute specifies the bean name of the thread factory to use to create worker threads. The nested “max-threads
” attribute may be used to specify the thread pool size. The nested “keepalive-time
” element is used to specify the amount of time that threads should be kept running when idle.
1 |
|
配置使用执行器
在web
节点下指定已定义的执行器(默认没有指定),新增配置executor="http-executor1"
,参考如下:
1 |
|
###