banxitan

          統(tǒng)計(jì)

          留言簿(2)

          閱讀排行榜

          評(píng)論排行榜

          JBOSS 下如何配置C3P0的連接池(解決Mysql 8小時(shí)的問題)

          JBOSS 下如何配置C3P0的連接池(解決Mysql 8小時(shí)的問題)

          問題引起:
              在公司配置文檔管理系統(tǒng)(OPENKM)時(shí),把數(shù)據(jù)源切換到Mysql數(shù)據(jù)源下,經(jīng)過測(cè)試,發(fā)現(xiàn)經(jīng)過8小時(shí)后,數(shù)據(jù)庫(kù)連接自動(dòng)斷開。

          解決辦法:
              把原來的openkm-ds.xml刪除掉。原openkm-ds.xml的內(nèi)容如下:
          <?xml version="1.0" encoding="UTF-8"?>

          <datasources>
          <!-- OpenKM User Activity -->
          <local-tx-datasource>
          <jndi-name>OKMActivityDS</jndi-name>
          <connection-url>jdbc:mysql://localhost:3306/openkm</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>root</user-name>
          <password>123456</password>
          <min-pool-size>5</min-pool-size>
          <max-pool-size>20</max-pool-size>
          <idle-timeout-minutes>0</idle-timeout-minutes>
          <track-statements/>
          <!--<security-domain>HsqlDbRealm</security-domain>-->
          <prepared-statement-cache-size>32</prepared-statement-cache-size>
          <metadata>
          <type-mapping>mySQL</type-mapping>
          </metadata>
          <!-- <depends>jboss:service=Hypersonic,database=OKMActivity</depends> -->
          </local-tx-datasource>

          <!-- OpenKM User Auth -->
          <local-tx-datasource>
          <jndi-name>OKMAuthDS</jndi-name>
          <connection-url>jdbc:mysql://localhost:3306/openkm</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>root</user-name>
          <password>123456</password>
          <min-pool-size>5</min-pool-size>
          <max-pool-size>20</max-pool-size>
          <idle-timeout-minutes>0</idle-timeout-minutes>
          <track-statements/>
          <!--<security-domain>HsqlDbRealm</security-domain>-->
          <prepared-statement-cache-size>32</prepared-statement-cache-size>
          <metadata>
          <type-mapping>mySQL</type-mapping>
          </metadata>
          <!--<depends>jboss:service=Hypersonic,database=OKMAuth</depends> -->
          </local-tx-datasource>
             
            
           
          <!-- OpenKM Dashboard Stats -->
          <local-tx-datasource>
          <jndi-name>OKMDashboardStatsDS</jndi-name>
          <connection-url>jdbc:mysql://localhost:3306/openkm</connection-url>
          <driver-class>com.mysql.jdbc.Driver</driver-class>
          <user-name>root</user-name>
          <password>123456</password>
          <min-pool-size>5</min-pool-size>
          <max-pool-size>20</max-pool-size>
          <idle-timeout-minutes>0</idle-timeout-minutes>
          <track-statements/>
          <!--<security-domain>HsqlDbRealm</security-domain>-->
          <prepared-statement-cache-size>32</prepared-statement-cache-size>
          <metadata>
          <type-mapping>mySQL</type-mapping>
          </metadata>
          <!-- <depends>jboss:service=Hypersonic,database=OKMDashboardStats</depends>-->
          </local-tx-datasource>

            
          <!-- OpenKM Workflow -->
            
          <local-tx-datasource>
              
          <jndi-name>OKMWorkflowDS</jndi-name>
              
          <connection-url>jdbc:mysql://localhost:3306/openkm</connection-url>
              
          <driver-class>com.mysql.jdbc.Driver</driver-class>
              
          <user-name>root</user-name>
              
          <password>123456</password>
              
          <min-pool-size>5</min-pool-size>
              
          <max-pool-size>20</max-pool-size>
              
          <idle-timeout-minutes>0</idle-timeout-minutes>
              
          <track-statements/>
              
          <!--<security-domain>HsqlDbRealm</security-domain>-->
              
          <prepared-statement-cache-size>32</prepared-statement-cache-size>
              
          <metadata>
                
          <type-mapping>mySQL</type-mapping>
              
          </metadata>
            
          </local-tx-datasource>
          </datasources>

          在{JBOSS_HOME}\server\default\deploy目錄下新建 c3p0-service.xml 文件;文件內(nèi)容如下
          <?xml version="1.0" encoding="UTF-8"?> 
          <!DOCTYPE server> 
          <server>
              
          <mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource" name="jboss:service=C3P0PooledDataSourceOKMWorkflowDS">
              
          <attribute name="JndiName">java:OKMWorkflowDS</attribute>
              
          <attribute name="JdbcUrl">jdbc:mysql://localhost:3306/openkm</attribute>
              
          <attribute name="DriverClass">com.mysql.jdbc.Driver</attribute>
              
          <attribute name="User">root</attribute>
              
          <attribute name="Password">123456</attribute>  
              
          <!-- Uncomment and set any of the optional parameters below -->  
              
          <!-- See c3p0's docs for more info. -->  
              
          <attribute name="AcquireIncrement">2</attribute>  
              
          <attribute name="AcquireRetryAttempts">30</attribute>  
              
          <!-- <attribute name="AcquireRetryDelay">1000</attribute> -->  
              
          <!-- <attribute name="AutoCommitOnClose">false</attribute> -->  
              
          <!-- <attribute name="AutomaticTestTable"></attribute> -->  
              
          <attribute name="BreakAfterAcquireFailure">true</attribute> 
              
          <!-- <attribute name="CheckoutTimeout">0</attribute> -->  
              
          <!-- <attribute name="ConnectionCustomizerClassName"></attribute> -->  
              
          <!-- <attribute name="ConnectionTesterClassName"></attribute> -->  
              
          <!-- <attribute name="Description">A pooled c3p0 DataSource</attribute> -->  
              
          <!-- <attribute name="DebugUnreturnedConnectionStackTraces">false</attribute> -->  
              
          <!-- <attribute name="FactoryClassLocation"></attribute> -->  
              
          <!-- <attribute name="ForceIgnoreUnresolvedTransactions">false</attribute> -->  
              
          <attribute name="IdleConnectionTestPeriod">40</attribute>  
              
          <attribute name="InitialPoolSize">2</attribute>  
              
          <!-- <attribute name="MaxAdministrativeTaskTime">0</attribute> -->  
              
          <!-- <attribute name="MaxConnectionAge">0</attribute> -->  
              
          <attribute name="MaxIdleTime">1800</attribute>
              
          <!-- <attribute name="MaxIdleTimeExcessConnections">0</attribute> -->  
              
          <attribute name="MaxPoolSize">15</attribute>  
              
          <attribute name="MaxStatements">0</attribute> 
              
          <!-- <attribute name="MaxStatementsPerConnection">0</attribute> -->  
              
          <attribute name="MinPoolSize">1</attribute> 
              
          <!-- <attribute name="NumHelperThreads">3</attribute> -->  
              
          <!-- <attribute name="PreferredTestQuery"></attribute> -->  
              
          <!-- <attribute name="TestConnectionOnCheckin">false</attribute> -->  
              
          <attribute name="TestConnectionOnCheckout">false</attribute> 
              
          <!-- <attribute name="UnreturnedConnectionTimeout">0</attribute> -->  
              
          <!-- <attribute name="UsesTraditionalReflectiveProxies">false</attribute> -->  
              
          <depends>jboss:service=Naming</depends>  
              
          </mbean>
              
          <mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource" name="jboss:service=C3P0PooledDataSourceOKMDashboardStatsDS">
              
          <attribute name="JndiName">java:OKMDashboardStatsDS</attribute>
              
          <attribute name="JdbcUrl">jdbc:mysql://localhost:3306/openkm</attribute>
              
          <attribute name="DriverClass">com.mysql.jdbc.Driver</attribute>
              
          <attribute name="User">root</attribute>
              
          <attribute name="Password">123456</attribute>  
              
          <!-- Uncomment and set any of the optional parameters below -->  
              
          <!-- See c3p0's docs for more info. -->  
              
          <attribute name="AcquireIncrement">2</attribute>  
              
          <attribute name="AcquireRetryAttempts">30</attribute>  
              
          <!-- <attribute name="AcquireRetryDelay">1000</attribute> -->  
              
          <!-- <attribute name="AutoCommitOnClose">false</attribute> -->  
              
          <!-- <attribute name="AutomaticTestTable"></attribute> -->  
              
          <attribute name="BreakAfterAcquireFailure">true</attribute> 
              
          <!-- <attribute name="CheckoutTimeout">0</attribute> -->  
              
          <!-- <attribute name="ConnectionCustomizerClassName"></attribute> -->  
              
          <!-- <attribute name="ConnectionTesterClassName"></attribute> -->  
              
          <!-- <attribute name="Description">A pooled c3p0 DataSource</attribute> -->  
              
          <!-- <attribute name="DebugUnreturnedConnectionStackTraces">false</attribute> -->  
              
          <!-- <attribute name="FactoryClassLocation"></attribute> -->  
              
          <!-- <attribute name="ForceIgnoreUnresolvedTransactions">false</attribute> -->  
              
          <attribute name="IdleConnectionTestPeriod">40</attribute>  
              
          <attribute name="InitialPoolSize">2</attribute>  
              
          <!-- <attribute name="MaxAdministrativeTaskTime">0</attribute> -->  
              
          <!-- <attribute name="MaxConnectionAge">0</attribute> -->  
              
          <attribute name="MaxIdleTime">1800</attribute>
              
          <!-- <attribute name="MaxIdleTimeExcessConnections">0</attribute> -->  
              
          <attribute name="MaxPoolSize">15</attribute>  
              
          <attribute name="MaxStatements">0</attribute> 
              
          <!-- <attribute name="MaxStatementsPerConnection">0</attribute> -->  
              
          <attribute name="MinPoolSize">1</attribute> 
              
          <!-- <attribute name="NumHelperThreads">3</attribute> -->  
              
          <!-- <attribute name="PreferredTestQuery"></attribute> -->  
              
          <!-- <attribute name="TestConnectionOnCheckin">false</attribute> -->  
              
          <attribute name="TestConnectionOnCheckout">false</attribute> 
              
          <!-- <attribute name="UnreturnedConnectionTimeout">0</attribute> -->  
              
          <!-- <attribute name="UsesTraditionalReflectiveProxies">false</attribute> -->  
              
          <depends>jboss:service=Naming</depends>  
              
          </mbean> 
              
          <mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource" name="jboss:service=C3P0PooledDataSourceOKMAuthDS">
              
          <attribute name="JndiName">java:OKMAuthDS</attribute>
              
          <attribute name="JdbcUrl">jdbc:mysql://localhost:3306/openkm</attribute>
              
          <attribute name="DriverClass">com.mysql.jdbc.Driver</attribute>
              
          <attribute name="User">root</attribute>
              
          <attribute name="Password">123456</attribute>  
              
          <!-- Uncomment and set any of the optional parameters below -->  
              
          <!-- See c3p0's docs for more info. -->  
              
          <attribute name="AcquireIncrement">2</attribute>  
              
          <attribute name="AcquireRetryAttempts">30</attribute>  
              
          <!-- <attribute name="AcquireRetryDelay">1000</attribute> -->  
              
          <!-- <attribute name="AutoCommitOnClose">false</attribute> -->  
              
          <!-- <attribute name="AutomaticTestTable"></attribute> -->  
              
          <attribute name="BreakAfterAcquireFailure">true</attribute> 
              
          <!-- <attribute name="CheckoutTimeout">0</attribute> -->  
              
          <!-- <attribute name="ConnectionCustomizerClassName"></attribute> -->  
              
          <!-- <attribute name="ConnectionTesterClassName"></attribute> -->  
              
          <!-- <attribute name="Description">A pooled c3p0 DataSource</attribute> -->  
              
          <!-- <attribute name="DebugUnreturnedConnectionStackTraces">false</attribute> -->  
              
          <!-- <attribute name="FactoryClassLocation"></attribute> -->  
              
          <!-- <attribute name="ForceIgnoreUnresolvedTransactions">false</attribute> -->  
              
          <attribute name="IdleConnectionTestPeriod">40</attribute>  
              
          <attribute name="InitialPoolSize">2</attribute>  
              
          <!-- <attribute name="MaxAdministrativeTaskTime">0</attribute> -->  
              
          <!-- <attribute name="MaxConnectionAge">0</attribute> -->  
              
          <attribute name="MaxIdleTime">1800</attribute>
              
          <!-- <attribute name="MaxIdleTimeExcessConnections">0</attribute> -->  
              
          <attribute name="MaxPoolSize">15</attribute>  
              
          <attribute name="MaxStatements">0</attribute> 
              
          <!-- <attribute name="MaxStatementsPerConnection">0</attribute> -->  
              
          <attribute name="MinPoolSize">1</attribute> 
              
          <!-- <attribute name="NumHelperThreads">3</attribute> -->  
              
          <!-- <attribute name="PreferredTestQuery"></attribute> -->  
              
          <!-- <attribute name="TestConnectionOnCheckin">false</attribute> -->  
              
          <attribute name="TestConnectionOnCheckout">false</attribute> 
              
          <!-- <attribute name="UnreturnedConnectionTimeout">0</attribute> -->  
              
          <!-- <attribute name="UsesTraditionalReflectiveProxies">false</attribute> -->  
              
          <depends>jboss:service=Naming</depends>  
              
          </mbean> 
              
          <mbean code="com.mchange.v2.c3p0.jboss.C3P0PooledDataSource" name="jboss:service=C3P0PooledDataSourceOKMActivityDS">
              
          <attribute name="JndiName">java:OKMActivityDS</attribute>
              
          <attribute name="JdbcUrl">jdbc:mysql://localhost:3306/openkm</attribute>
              
          <attribute name="DriverClass">com.mysql.jdbc.Driver</attribute>
              
          <attribute name="User">root</attribute>
              
          <attribute name="Password">123456</attribute>  
              
          <!-- Uncomment and set any of the optional parameters below -->  
              
          <!-- See c3p0's docs for more info. -->  
              
          <attribute name="AcquireIncrement">2</attribute>  
              
          <attribute name="AcquireRetryAttempts">30</attribute>  
              
          <!-- <attribute name="AcquireRetryDelay">1000</attribute> -->  
              
          <!-- <attribute name="AutoCommitOnClose">false</attribute> -->  
              
          <!-- <attribute name="AutomaticTestTable"></attribute> -->  
              
          <attribute name="BreakAfterAcquireFailure">true</attribute> 
              
          <!-- <attribute name="CheckoutTimeout">0</attribute> -->  
              
          <!-- <attribute name="ConnectionCustomizerClassName"></attribute> -->  
              
          <!-- <attribute name="ConnectionTesterClassName"></attribute> -->  
              
          <!-- <attribute name="Description">A pooled c3p0 DataSource</attribute> -->  
              
          <!-- <attribute name="DebugUnreturnedConnectionStackTraces">false</attribute> -->  
              
          <!-- <attribute name="FactoryClassLocation"></attribute> -->  
              
          <!-- <attribute name="ForceIgnoreUnresolvedTransactions">false</attribute> -->  
              
          <attribute name="IdleConnectionTestPeriod">40</attribute>  
              
          <attribute name="InitialPoolSize">2</attribute>  
              
          <!-- <attribute name="MaxAdministrativeTaskTime">0</attribute> -->  
              
          <!-- <attribute name="MaxConnectionAge">0</attribute> -->  
              
          <attribute name="MaxIdleTime">1800</attribute>
              
          <!-- <attribute name="MaxIdleTimeExcessConnections">0</attribute> -->  
              
          <attribute name="MaxPoolSize">15</attribute>  
              
          <attribute name="MaxStatements">0</attribute> 
              
          <!-- <attribute name="MaxStatementsPerConnection">0</attribute> -->  
              
          <attribute name="MinPoolSize">1</attribute> 
              
          <!-- <attribute name="NumHelperThreads">3</attribute> -->  
              
          <!-- <attribute name="PreferredTestQuery"></attribute> -->  
              
          <!-- <attribute name="TestConnectionOnCheckin">false</attribute> -->  
              
          <attribute name="TestConnectionOnCheckout">false</attribute> 
              
          <!-- <attribute name="UnreturnedConnectionTimeout">0</attribute> -->  
              
          <!-- <attribute name="UsesTraditionalReflectiveProxies">false</attribute> -->  
              
          <depends>jboss:service=Naming</depends>  
              
          </mbean> 
              
          </server>

          最后一步,把C3P0的JAR c3p0-09.1.11.jar COPY 到{JBOSS_HOME}\server\default\lib 目錄下即可。




          posted on 2010-01-19 17:28 MikyTan 閱讀(3187) 評(píng)論(0)  編輯  收藏 所屬分類: JAVA

          主站蜘蛛池模板: 新干县| 天台县| 博乐市| 兖州市| 竹溪县| 呼伦贝尔市| 灵台县| 获嘉县| 曲水县| 正镶白旗| 中山市| 安阳县| 汝城县| 万山特区| 永川市| 阿拉尔市| 印江| 曲阳县| 东乌珠穆沁旗| 醴陵市| 三台县| 郯城县| 濉溪县| 阜城县| 江安县| 句容市| 洛川县| 通城县| 马边| 晋江市| 砚山县| 舞阳县| 南皮县| 尉氏县| 安顺市| 吉木乃县| 乾安县| 无棣县| 中方县| 博白县| 灵川县|