16.2. 连接器配置


总结

JBoss EAP 6 里的线程池可以通过 Executor 模型在不同组件间共享。这些池不仅可以由不同的 HTTP 连接器共享,也可以被JBoss EAP 6 里支持 Executor 模型的其他组件共享。通过 HTTP 连接器线程池来满足当前的 Web 性能要求是件难办的事,它要求密切监控当前的线程池以及于其的负载需求。在本节里,您会学习如何通过 Executor 模型为 HTTP 连接器设立线程池。您也会学习通过命令行界面或编辑 XML 配置文件来进行设置。

过程 16.1. 为 HTTP 连接器设立线程池

  1. 定义线程工厂

    打开配置文件 standalone.xml(独立服务器)或 domain.xml(受管域)。这个文件位于 EAP_HOME/standalone/configurationEAP_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>	
    
    
    Copy to Clipboard Toggle word wrap
    如果您想用 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")
    Copy to Clipboard Toggle word wrap
  2. 创建执行器(Executor)

    您可以使用六种内置的 Executor 类来充当这个工厂的执行器。这六种执行器是:unbounded-queue-thread-poolbounded-queue-thread-poolblocking-bounded-queue-thread-poolqueueless-thread-poolblocking-queueless-thread-poolscheduled-thread-pool
    在这个例子里,我们将使用 unbounded-queue-thread-pool 来充当执行器。修改 max-threadskeepalive-time 参数的值来满足您的服务器的需要。
    <unbounded-queue-thread-pool name="uq-thread-pool">
      <thread-factory name="http-connector-factory" />
      <max-threads count="10" />
      <keepalive-time time="30" unit="seconds" />
    </unbounded-queue-thread-pool>			
    
    
    Copy to Clipboard Toggle word wrap
    或者您更愿意使用 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)
    Copy to Clipboard Toggle word wrap
  3. 让 HTTP 连接器使用这个线程池

    在相同的配置文件里,找到 web 子系统下的 HTTP 连接器元素并进行修改,让它使用之前步骤里定义的线程池。
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" executor="uq-thread-pool" />
    
    Copy to Clipboard Toggle word wrap
    或者您更愿意使用 CLI:
    [standalone@localhost:9999 /] ./subsystem=web/connector=http:write-attribute(name=executor, value="uq-thread-pool")
    Copy to Clipboard Toggle word wrap
  4. 重启服务器

    重启服务器(独立服务器或受管域)让修改可以生效。请用下列 CLI 命令来确认上面步骤里的修改已经生效:
    [standalone@localhost:9999 /] ./subsystem=threads:read-resource(recursive=true)
    {                  
        "outcome" => "success",
        "result" => {
            "blocking-bounded-queue-thread-pool" => undefined,
            "blocking-queueless-thread-pool" => undefined,
            "bounded-queue-thread-pool" => undefined,
            "queueless-thread-pool" => undefined,
            "scheduled-thread-pool" => undefined,
            "thread-factory" => {"http-connector-factory" => {
                "group-name" => "uq-thread-pool",
                "name" => "http-connector-factory",
                "priority" => 9,
                "thread-name-pattern" => "HTTP-%t"
            }},
            "unbounded-queue-thread-pool" => {"uq-thread-pool" => {
                "keepalive-time" => {
                    "time" => 30L,
                    "unit" => "SECONDS"
                },
                "max-threads" => 30,
                "name" => "uq-thread-pool",
                "thread-factory" => "http-connector-factory"
            }}
        }
    }
    [standalone@localhost:9999 /] ./subsystem=web/connector=http:read-resource(recursive=true)
    {
        "outcome" => "success",
        "result" => {
            "configuration" => undefined,
            "enable-lookups" => false,
            "enabled" => true,
            "executor" => "uq-thread-pool",
            "max-connections" => undefined,
            "max-post-size" => 2097152,
            "max-save-post-size" => 4096,
            "name" => "http",
            "protocol" => "HTTP/1.1",
            "proxy-name" => undefined,
            "proxy-port" => undefined,
            "redirect-port" => 443,
            "scheme" => "http",
            "secure" => false,
            "socket-binding" => "http",
            "ssl" => undefined,
            "virtual-server" => undefined
        }
    }
    
    Copy to Clipboard Toggle word wrap
结果

您已经创建一个线程工厂和执行器,而且修改了 HTTP 连接器来使用这个线程池。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat