2

当数据库和 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>

4

2 回答 2

5

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

                <validation>
                    <check-valid-connection-sql>select 1</check-valid-connection-sql>
                    <background-validation>true</background-validation>
                    <background-validation-millis>15000</background-validation-millis>
                </validation>
于 2015-01-12T15:17:02.003 回答
1

一个适用于 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的是,它通过供应商特定的机制验证连接。

于 2016-06-06T14:52:45.717 回答