Jboss AS7连接池不会重新连接 [英] Jboss AS7 connection pool won't reconnect

查看:103
本文介绍了Jboss AS7连接池不会重新连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 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>

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

If, for some reason, the database stop responding for a second, JBoss can't reconnect and I have to restart the app server.

但是,如果我将数据源更改为 xa -datasource (保持配置与示例中相同),使用 org.postgresql.xa.PGXADataSource 驱动程序,它有效

But, If I change the datasource to xa-datasource (keeping the config as it is in the example) using the org.postgresql.xa.PGXADataSource driver, it works.

事实是:我对此毫无道理。如果我错了,请纠正我,但是 xa-datasources 应该用于同步提交多个数据库,在这里不是这种情况。我实际上配置了多个数据库,但是我不需要在它们之间同步事务。

Thing is: I can't make sense out of this. Correct me if I'm wrong, but xa-datasources are supposed to be used to synchronously commit in more than one database, and that's not the case here. I actually have more than one database configured, but I don't need to sync the transactions between them.

默认 数据源似乎也无法确定连接池的大小。有时,与应用程序的负载无关紧要,它会打开100个以上的连接(即使限制为100个),并在几秒钟后关闭它们。这很难再现-因为它似乎是随机的,所以,我不能肯定地说切换到 xa-datasource 也可以解决此问题。

The "default" datasource also seems to have problems with sizing the connection pool. Sometimes, doesn't matter the load of the app, it opens more than 100 connections (even if the limit is 100) and closes them after some seconds. This is hard to reproduce - because it seems random, so, I can't tell for sure that switching to xa-datasource solves this problem too.

现在:


  • 为什么要切换到 xa-datasource 有效吗?

  • 这样做的含义是什么?

  • 为什么连接池如此疯狂?

  • why switching to xa-datasource works?
  • what are the implications of doing this?
  • why connection pool is going crazy like this?

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

Just to clarify, my test consists in:


  1. 启动postgres和应用服务器;

  2. 对应用程序进行一些请求;

  3. 停止数据库;

  4. 向应用程序发送一些请求-并发现它们无法正常工作,因为它无法打开任何连接;

  5. 再次启动数据库;

  6. 对应用程序进行一些请求

  1. start up postgres and the app server;
  2. do some requests to the application;
  3. stop the database;
  4. do some requests to the application - and see that they are not working because it can't open any connections;
  5. start up the database again;
  6. do some requests to the application

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

In the last step, xa-datasource can reconnect with postgres and everything works. datasource can't, and fails forever, load doesn't matter - I have to restart the app server.

推荐答案

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

One thing to remember when configuring jboss is that sometimes the best documentation is in the projects for the individual components. In the case of datasource settings, I always tell people to check out the IronJacamar docs: http://www.ironjacamar.org/doc/userguide/1.0/en-US/html_single/

要执行以下操作,这些设置应该可以正常工作:

for what you want to do, these settings should work:

<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>

这篇关于Jboss AS7连接池不会重新连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆