我正在使用Hibernate中的EntityManagerFactory
,并且connectionPoolSize为20。现在我有一些较大的查询(t> 30分钟)完全占用了我的池。当我使用getEntityManager启动新查询时,出现以下异常:
javax.persistence.PersistenceException: org.hibernate.HibernateException:
The internal connection pool has reached its maximum size and no connection is currently available!
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:154)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:181)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1538)
at org.hibernate.query.Query.getResultList(Query.java:165)
在连接可用之前,是否有任何舒适功能会使我的线程进入睡眠状态?
我只使用标准功能:
public static EntityManager getEntityManager () {
return emFactory.createEntityManager ();
}
我的EntityManagerFactory的创建:
public static void createEntityManagerFactory(String hostname, Integer port, String driver,
String database, boolean validate, int maxConnections, Properties properties) {
Properties props = new Properties();
props.setProperty("hibernate.connection.url", "jdbc:" + driver + ":thin:@" + hostname + ":" + port + ":" + database);
props.setProperty("hibernate.connection.driver_class", "oracle.jdbc.driver.OracleDriver");
props.setProperty("hibernate.connection.username", properties.getProperty("user"));
props.setProperty("hibernate.connection.password", properties.getProperty("password"));
props.setProperty("hibernate.dialect", "org.hibernate.dialect.Oracle10gDialect");
emFactory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME, props);
}
我的persistence.xml包含:
<property name="connection.pool_size" value="20" />
我阅读了有关C3P0设置的信息,它们对我有帮助吗?
-更新-我在使用C3P0时遇到了一些问题(例如:ORA-01652:即使有很少的最大连接池大小,也无法在表空间SYSTEM中将temp段扩展128)香草。 - 配置c3p0
<property name="hibernate.c3p0.min_size" value ="2"/>
<property name="hibernate.c3p0.max_size" value ="10"/>
<property name="hibernate.c3p0.acquire_increment" value ="2"/>
<property name="hibernate.c3p0.idle_test_period" value ="100"/>
<property name="hibernate.c3p0.timeout" value ="3600"/>