当我们通过Intellij在本地运行作业时,它可以正常工作。
当我们在服务器上部署相同的代码并在服务器上运行时,它可以正常一次,但如果我们尝试立即再次运行相同的作业, 花费太长时间来创建实体管理器(有时5分钟,有时20分钟......随机但太长)。
它停留在EntityManager em = getFactory(id).createEntityManager(finalProps);在EntityManagerCreator类中。
它可以是打开的连接数(?) - 如果前一个实体经理没有正确关闭..但我正在这样做......
由于我的代码太长,所以我创建了一个演示程序,它正在执行相同的操作......下面是我的代码,但这也表现得同样......
public void cleanupRestorePoint(final String jobName, final String stepName) throws SQLException {
Map pmap = new HashMap();
pmap.put("javax.persistence.jdbc.url", "jdbc:oracle:thin:@XXXXX");
pmap.put("javax.persistence.jdbc.password", "aaaa");
pmap.put("javax.persistence.jdbc.user", "bbb");
EntityManagerFactory emf = Persistence.createEntityManagerFactory("JpaDm", pmap);
Connection connection = null;
EntityManager em = null;
try {
em = emf.createEntityManager(pmap);
connection = em.unwrap(Connection.class);
Map<String, Object> properties = emf.getProperties();
System.out.println("pro" + properties);
EntityTransaction transaction = em.getTransaction();
transaction.begin();
//to do
transaction.commit();
} catch (Exception e) {
e.printStackTrace();
}finally{
em.clear();
em.close();
emf.close();
}}
的persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.0"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="JpaDm" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<!-- This property is dynamically set from the application if the DataSource is configured -->
<!-- It will also overwrite the following 4 properties - the DB connection ones -->
<!-- <property name="javax.persistence.nonJtaDataSource" value="java:/comp/env/jdbc/aaaa" /> -->
<property name="javax.persistence.jdbc.driver" value="oracle.jdbc.OracleDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:oracle:thin:@localhost:1521:orcl" />
<property name="javax.persistence.jdbc.user" value="aaaaa" />
<property name="javax.persistence.jdbc.password" value="vvvv" />
<property name="eclipselink.target-database"
value="org.eclipse.persistence.platform.database.oracle.OraclePlatform"/>
<!-- issues with Primitive collections validation -->
<property name="javax.persistence.validation.mode" value="NONE" />
<property name="eclipselink.session.customizer"
value="com.bphx.adaprep.support.ELSessionCustomizer" />
<!-- <property name="eclipselink.jdbc.batch-writing" value="JDBC"/> -->
<property name="eclipselink.jdbc.batch-writing" value="oracle-jdbc" />
<property name="eclipselink.jdbc.batch-writing.size" value="1000"/>
<!-- Logging -->
<property name="eclipselink.logging.level" value="WARNING" />
<!-- property name="eclipselink.profiler" value="PerformanceProfiler"/ -->
<property name="eclipselink.logging.timestamp" value="true" />
<property name="eclipselink.logging.session" value="false" />
<property name="eclipselink.logging.thread" value="false" />
<property name="eclipselink.ddl-generation.output-mode" value="sql-script" />
<!-- Needed to add custom indexes -->
<!-- property name="javax.persistence.sql-load-script-source" value="META-INF/sqlinit.sql" /> -->
<!-- UNCOMMENT FOR DDL GENERATION / DROP CREATE -->
<!--
<property name="eclipselink.ddl-generation" value="drop-and-create-tables" />
<property name="eclipselink.application-location" value="dm" />
<property name="eclipselink.create-ddl-jdbc-file-name" value="createDDL.jdbc" />
<property name="eclipselink.drop-ddl-jdbc-file-name" value="dropDDL.jdbc" />
<property name="eclipselink.ddl-generation.output-mode" value="both" /
-->
<property name="eclipselink.session-event-listener" value="com.bphx.adaprep.config.ConverterInitializer" />
<!-- Disable weaving - comment for production usage -->
<property name="eclipselink.connection-pool.min" value="10"/>
<property name="eclipselink.connection-pool.max" value="400"/>
<property name="eclipselink.connection-pool.wait" value="100"/>
<property name="eclipselink.weaving" value="false" />
</properties>
</persistence-unit>
</persistence>
请告诉我有什么办法可以阻止它的挂起.. 如果有任何泄露的资源我如何检查它们?这段代码在本地工作正常,但在Dev环境中提出问题,我没有第三个环境来测试它。