重启/断开数据库时,JBoss自动重新连接数据库

时间:2013-09-23 10:53:55

标签: oracle jboss

当数据库和JBoss之间断开连接时,是否有任何版本的JBoss支持自动重新连接数据库?我在

中尝试了以下配置
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
   <datasources>    
    <local-tx-datasource>
   <jndi-name>sampleDS</jndi-name>
   <min-pool-size>1</min-pool-size>
    <max-pool-size>5</max-pool-size>
    <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
    <connection-url>jdbc:oracle:thin:@<ip>:<databaseport>:<sip></connection-url>
    <user-name>username</user-name>
    <password>password</password>
    <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
    <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
    <check-valid-connection-sql>SELECT 1 FROM DUAL</check-valid-connection-sql>
<failOverReadOnly>false</failOverReadOnly>
<autoReconnect>true</autoReconnect>
     <maxReconnects>50</maxReconnects>
     <initialTimeout>15</initialTimeout>
     </local-tx-datasource>

2 个答案:

答案 0 :(得分:3)

我正在使用jboss-eap-6.1,它的工作正常。修改jboss-eap-6.1 / standalone / configuration / standalone.xml文件,并在每个<xa-datasource>标记内添加以下行。

                <validation>
                    <check-valid-connection-sql>select 1</check-valid-connection-sql>
                    <background-validation>true</background-validation>
                    <background-validation-millis>15000</background-validation-millis>
                </validation>

答案 1 :(得分:0)

JBoss EAP 6.4(基于JBoss AS 7.x)+ Oracle的一个例子:

<datasource>
    <validation>
        <valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
        <background-validation>true</background-validation>
        <background-validation-millis>5000</background-validation-millis>
    </validation>

select 1 from dual不同,它通过供应商特定机制验证连接。