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 无法重新连接,我必须重新启动应用程序服务器。
但是,如果我使用驱动程序更改datasource
为xa-datasource
(保持示例中的配置不变)org.postgresql.xa.PGXADataSource
,它会起作用。
事情是:我无法理解这一点。如果我错了,请纠正我,但xa-datasources
应该用于在多个数据库中同步提交,而这里并非如此。我实际上配置了不止一个数据库,但我不需要同步它们之间的事务。
“默认”datasource
似乎在调整连接池大小方面也有问题。有时,与应用程序的负载无关,它会打开 100 多个连接(即使限制为 100)并在几秒钟后关闭它们。这很难重现 - 因为它看起来是随机的,所以,我不能确定切换到也能xa-datasource
解决这个问题。
现在:
xa-datasource
作品?为了澄清,我的测试包括:
在最后一步,xa-datasource
可以重新连接 postgres,一切正常。datasource
不能,并且永远失败,负载无关紧要 - 我必须重新启动应用程序服务器。
配置 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)
归档时间: |
|
查看次数: |
5093 次 |
最近记录: |