Jboss AS7 连接池不会重新连接

caa*_*os0 5 java postgresql jboss7.x

我的配置中有以下配置standalone.xml

<subsystem xmlns="urn:jboss:domain:datasources:1.1">
    <datasources>
        <datasource jta="true" jndi-name="java:/jdbc/myds" pool-name="CADS" enabled="true" use-java-context="true" use-ccm="true">
            <connection-url>jdbc:postgresql://db.host/name</connection-url>
            <driver>postgresql</driver>
            <new-connection-sql>select 1</new-connection-sql>
            <pool>
                <min-pool-size>20</min-pool-size>
                <max-pool-size>100</max-pool-size>
                <flush-strategy>IdleConnections</flush-strategy>
            </pool>
            <security>
                <user-name>user</user-name>
                <password>pwd</password>
            </security>
            <validation>
                <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
                <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>
            </validation>
            <timeout>
                <blocking-timeout-millis>30000</blocking-timeout-millis>
                <idle-timeout-minutes>1</idle-timeout-minutes>
            </timeout>
            <statement>
                <track-statements>true</track-statements>
            </statement>
        </datasource>
        <drivers>
            <driver name="postgresql" module="org.postgresql">
                <xa-datasource-class>org.postgresql.Driver</xa-datasource-class>
            </driver>
        </drivers>
    </datasources>
</subsystem>
Run Code Online (Sandbox Code Playgroud)

如果由于某种原因,数据库停止响应一秒钟,JBoss 无法重新连接,我必须重新启动应用程序服务器。

但是,如果我使用驱动程序更改datasourcexa-datasource(保持示例中的配置不变)org.postgresql.xa.PGXADataSource它会起作用

事情是:我无法理解这一点。如果我错了,请纠正我,但xa-datasources应该用于在多个数据库中同步提交,而这里并非如此。我实际上配置了不止一个数据库,但我不需要同步它们之间的事务。

“默认”datasource似乎在调整连接池大小方面也有问题。有时,与应用程序的负载无关,它会打开 100 多个连接(即使限制为 100)并在几秒钟后关闭它们。这很难重现 - 因为它看起来是随机的,所以,我不能确定切换到也能xa-datasource解决这个问题。

现在:

  • 为什么切换到xa-datasource作品?
  • 这样做有什么影响?
  • 为什么连接池会像这样发疯?

为了澄清,我的测试包括:

  1. 启动 postgres 和应用服务器;
  2. 对应用程序做一些请求;
  3. 停止数据库;
  4. 向应用程序发出一些请求 - 并看到它们无法工作,因为它无法打开任何连接;
  5. 再次启动数据库;
  6. 对应用程序做一些请求

在最后一步,xa-datasource可以重新连接 postgres,一切正常。datasource不能,并且永远失败,负载无关紧要 - 我必须重新启动应用程序服务器。

tea*_*ran 5

配置 jboss 时要记住的一件事是,有时最好的文档是各个组件的项目。在数据源设置的情况下,我总是告诉人们查看 IronJacamar 文档:http : //www.ironjacamar.org/doc/userguide/1.0/en-US/html_single/

对于您想要做的事情,这些设置应该有效:

<validation>
    <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLValidConnectionChecker"/>
    <exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.postgres.PostgreSQLExceptionSorter"/>

    <!-- I don't know what this does but someone on my DevOps 
    team said to set it this way. :) -->
    <validate-on-match>false</validate-on-match>

    <!-- validate the connection using a background 
    thread rather than right before you try to use the connection -->
    <background-validation>true</background-validation>

    <!-- sets the frequency the background thread will check each connection.
    The lower this setting, the quicker it will find a bad connection 
    but it will be more chatty sending the validations to the server -->
    <background-validation-millis>60000</background-validation-millis>

    <!-- fast fail will mark all the connections invalid as soon as 
    it finds a bad one. This will make it clear the pool quicker 
    if all connections are reset at once such as a restart. Fast 
    fail would be trouble though if you had a setup where the database
    sometimes selectively kills a single connection, such as killing long
    running queries. -->
    <use-fast-fail>true</use-fast-fail>

</validation>
Run Code Online (Sandbox Code Playgroud)

  • 我添加了有关不同参数的评论。 (2认同)