如果没有任何反应,MySQL将在一段时间后关闭连接(8 hours by default).时间可能受配置中的wait_timeout变量影响.
我有一个Eclipse RCP应用程序,在其中使用EclipseLink作为持久性框架,当客户端超过超时时,我得到一个错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException:
No operations allowed after connection closed.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
...
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
...
com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException
...
org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor...
我试图设置autoReconnect / autoReconnectForPools = true,但这无济于事.
谢谢
编辑
在我的persistence.xml中,设置了以下属性:
name="eclipselink.jdbc.read-connections.max"
value="10" />
name="eclipselink.jdbc.cache-statements"
value="true" />
name="eclipselink.jdbc.read-connections.shared"
value="true" />
其余的配置在代码中完成:
Map map = ...
map.put(PersistenceUnitProperties.JDBC_URL,...);
map.put(PersistenceUnitProperties.JDBC_USER,...);
map.put(PersistenceUnitProperties.JDBC_PASSWORD, ...);
map.put(PersistenceUnitProperties.JDBC_DRIVER, ...);
map.put(PersistenceUnitProperties.CLASSLOADER, this.getClass()
.getClassLoader());
map.put(PersistenceUnitProperties.TARGET_DATABASE, "MySQL");
entityManagerFactory = new PersistenceProvider()
.createEntityManagerFactory("...", map);