16.2. 连接器配置
16.2.1. 为 JBoss EAP 6 里的 HTTP 连接器定义线程池 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
总结
JBoss EAP 6 里的线程池可以通过 Executor 模型在不同组件间共享。这些池不仅可以由不同的 HTTP 连接器共享,也可以被JBoss EAP 6 里支持 Executor 模型的其他组件共享。通过 HTTP 连接器线程池来满足当前的 Web 性能要求是件难办的事,它要求密切监控当前的线程池以及于其的负载需求。在本节里,您会学习如何通过 Executor 模型为 HTTP 连接器设立线程池。您也会学习通过命令行界面或编辑 XML 配置文件来进行设置。
过程 16.1. 为 HTTP 连接器设立线程池
定义线程工厂
打开配置文件standalone.xml
(独立服务器)或domain.xml
(受管域)。这个文件位于EAP_HOME/standalone/configuration
或EAP_HOME/domain/configuration
目录。添加下列子系统条目,按照您的服务器的需要修改相关的值。<subsystem xmlns="urn:jboss:domain:threads:1.0"> <thread-factory name="http-connector-factory" thread-name-pattern="HTTP-%t" priority="9" group-name="uq-thread-pool"/> </subsystem>
<subsystem xmlns="urn:jboss:domain:threads:1.0"> <thread-factory name="http-connector-factory" thread-name-pattern="HTTP-%t" priority="9" group-name="uq-thread-pool"/> </subsystem>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 如果您想用 CLI 来完成这个任务,请在 CLI 命令行提示下执行下列命令:[standalone@localhost:9999 /] ./subsystem=threads/thread-factory=http-connector-factory:add(thread-name-pattern="HTTP-%t", priority="9", group-name="uq-thread-pool")
[standalone@localhost:9999 /] ./subsystem=threads/thread-factory=http-connector-factory:add(thread-name-pattern="HTTP-%t", priority="9", group-name="uq-thread-pool")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 创建执行器(Executor)
您可以使用六种内置的 Executor 类来充当这个工厂的执行器。这六种执行器是:unbounded-queue-thread-pool
、bounded-queue-thread-pool
、blocking-bounded-queue-thread-pool
、queueless-thread-pool
、blocking-queueless-thread-pool
和scheduled-thread-pool
。在这个例子里,我们将使用unbounded-queue-thread-pool
来充当执行器。修改max-threads
和keepalive-time
参数的值来满足您的服务器的需要。Copy to Clipboard Copied! Toggle word wrap Toggle overflow 或者您更愿意使用 CLI:[standalone@localhost:9999 /] ./subsystem=threads/unbounded-queue-thread-pool=uq-thread-pool:add(thread-factory="http-connector-factory", keepalive-time={time=30, unit="seconds"}, max-threads=30)
[standalone@localhost:9999 /] ./subsystem=threads/unbounded-queue-thread-pool=uq-thread-pool:add(thread-factory="http-connector-factory", keepalive-time={time=30, unit="seconds"}, max-threads=30)
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 让 HTTP 连接器使用这个线程池
在相同的配置文件里,找到 web 子系统下的 HTTP 连接器元素并进行修改,让它使用之前步骤里定义的线程池。<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" executor="uq-thread-pool" />
<connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" executor="uq-thread-pool" />
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 或者您更愿意使用 CLI:[standalone@localhost:9999 /] ./subsystem=web/connector=http:write-attribute(name=executor, value="uq-thread-pool")
[standalone@localhost:9999 /] ./subsystem=web/connector=http:write-attribute(name=executor, value="uq-thread-pool")
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 重启服务器
重启服务器(独立服务器或受管域)让修改可以生效。请用下列 CLI 命令来确认上面步骤里的修改已经生效:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
结果
您已经创建一个线程工厂和执行器,而且修改了 HTTP 连接器来使用这个线程池。