我将WildFly V 10.1.0与Mysql数据库一起使用。
我在standalone.xml
中的数据源配置中将最大池大小定义为100但是我仍然会遇到异常[1];
我没有看到任何网络问题。我需要添加哪些其他设置?
我的persistence.xml
<persistence-unit name="adb-persistence-unit"
transaction-type="JTA">
<description>Forge Persistence Unit</description>
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/testDS</jta-data-source>
<shared-cache-mode>ALL</shared-cache-mode>
<property name="jboss.as.jpa.providerModule" value="org.hibernate:5.2"/>
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.max_size" value="500" />
<property name="hibernate.c3p0.timeout" value="1800" />
<property name="hibernate.c3p0.max_statements" value="100" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
<property name="hibernate.c3p0.acquire_increment" value="5" />
<property name="hibernate.c3p0.validate" value="false" />
我打开会话就像;
@PersistenceContext
protected EntityManager entityManager;
private Criteria criteria;
private Session session;
session = getEntityManager().unwrap(Session.class);
[1]
/20/2016 9:52:04 AMCaused by: java.sql.SQLException: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/testDS
10/20/2016 9:52:04 AM at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:146)
10/20/2016 9:52:04 AM at org.jboss.as.connector.subsystems.datasources.WildFlyDataSource.getConnection(WildFlyDataSource.java:66)
10/20/2016 9:52:04 AM at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
10/20/2016 9:52:04 AM at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)
10/20/2016 9:52:04 AM at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:99)
10/20/2016 9:52:04 AM ... 225 more
10/20/2016 9:52:04 AMCaused by: javax.resource.ResourceException: IJ000453: Unable to get managed connection for java:jboss/datasources/testDS
10/20/2016 9:52:04 AM at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:656)
10/20/2016 9:52:04 AM at org.jboss.jca.core.connectionmanager.tx.TxConnectionManagerImpl.getManagedConnection(TxConnectionManagerImpl.java:429)
10/20/2016 9:52:04 AM at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.allocateConnection(AbstractConnectionManager.java:747)
10/20/2016 9:52:04 AM at org.jboss.jca.adapters.jdbc.WrapperDataSource.getConnection(WrapperDataSource.java:138)
10/20/2016 9:52:04 AM ... 229 more
10/20/2016 9:52:04 AMCaused by: javax.resource.ResourceException: IJ000655: No managed connections available within configured blocking timeout (30000 [ms])
10/20/2016 9:52:04 AM at org.jboss.jca.core.connectionmanager.pool.mcp.SemaphoreConcurrentLinkedDequeManagedConnectionPool.getConnection(SemaphoreConcurrentLinkedDequeManagedConnectionPool.java:565)
10/20/2016 9:52:04 AM at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getTransactionNewConnection(AbstractPool.java:699)
10/20/2016 9:52:04 AM at org.jboss.jca.core.connectionmanager.pool.AbstractPool.getConnection(AbstractPool.java:598)
10/20/2016 9:52:04 AM at org.jboss.jca.core.connectionmanager.AbstractConnectionManager.getManagedConnection(AbstractConnectionManager.java:590)
10/20/2016 9:52:04 AM ... 232 more
10/20/
修改
数据源
<datasources>
<datasource jndi-name="java:jboss/datasources/testDS" pool-name="lobDS" enabled="true" use-java-context="true" use-ccm="true">
<connection-url>jdbc:mysql://${env.MYSQL_PORT_3306_TCP_ADDR:db.xx.com}:${env.MYSQL_PORT_3306_TCP_PORT:3306}/${env.MYSQL_DATABASE:testdb}?failOverReadOnly=false&maxReconnects=10&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=UTF-8&characterSetResults=UTF-8&useUnicode=true&interactiveClient=true&sessionVariables=storage_engine=InnoDB</connection-url>
<driver>mysql</driver>
<pool>
<flush-strategy>IdleConnections</flush-strategy>
<max-pool-size>100</max-pool-size>
</pool>
<security>
<user-name>${env.MYSQL_USER:admin}</user-name>
<password>${env.MYSQL_PASSWORD:ss_password}</password>
</security>
<validation>
<check-valid-connection-sql>SELECT 1</check-valid-connection-sql>
<background-validation>true</background-validation>
<background-validation-millis>60000</background-validation-millis>
</validation>
</datasource>