我的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无法重新连接,我必须重新启动应用服务器。
但是,如果我使用datasource
驱动程序将xa-datasource
更改为xa-datasource
(保持配置不变),那么就会工作。
问题是:我无法理解这一切。如果我错了,请纠正我,但是应该使用xa-datasources
在多个数据库中同步提交,这里不是这样的。实际上,我配置了多个数据库,但不需要同步它们之间的事务。
“默认”datasource
似乎在调整连接池的大小方面也有问题。有时候,不管应用程序的负载如何,它会打开100多个连接(即使限制是100),并在几秒钟后关闭它们。这是很难再现的-因为它似乎是随机的,所以,我不能肯定,切换到xa-datasource
也解决了这个问题。
现在:
xa-datasource
呢?为了澄清一下,我的测试包括:
在最后一步中,xa-datasource
可以重新连接postgres,一切都正常。datasource
不能,而且永远失败,加载并不重要--我必须重新启动应用服务器。
发布于 2015-08-15 10:01:17
在配置jboss时要记住的一件事是,有时最好的文档是在各个组件的项目中。在数据源设置的情况下,我总是告诉人们检查IronJacamar文档:单一/
对于您想要做的事情,这些设置应该有效:
<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>
发布于 2015-08-15 14:27:50
我想你错过了:<check-valid-connection-sql>select 1</check-valid-connection-sql>
in <validation>
部分
PS
PostgreSQLValidConnectionChecker.isValidConnection将空查询发送给postgres stmt.execute("");
,我认为postgres驱动程序忽略它。XA连接最有可能发送一些系统SQL语句来支持XA事务并获取SQLException。
https://stackoverflow.com/questions/32011550
复制相似问题