【问题标题】:Eclipselink factory.createEntityManager() stalls with more than one instance runningEclipselink factory.createEntityManager() 停止运行多个实例
【发布时间】:2010-03-26 10:39:21
【问题描述】:

使用我的 RCP 程序时,我遇到的问题是我希望在我的 PC 上运行多个副本。第一个实例运行得很好。 如果我启动第二个实例,一切都很好,直到我想访问数据库。

使用此代码:

..    
Map properties = new HashMap();
            properties.put("javax.persistence.jdbc.driver", dbDriver);
            properties.put("javax.persistence.jdbc.url", dbUrl);
            properties.put("javax.persistence.jdbc.user", dbUser);
            properties.put("javax.persistence.jdbc.password", dbPass);
            try {
                factory = Persistence.createEntityManagerFactory(
                        PERSISTENCE_UNIT_NAME, properties);
            } catch (Exception e) {
                System.out.println(e);
            }
            em=factory.createEntityManager(); // the second instance stops here
    ...

带有一个persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
    xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="default">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider> 

        <class>myclasshere</class>


        <properties>
            <property name="eclipselink.ddl-generation" value="create-tables" />
            <property name="eclipselink.ddl-generation.output-mode" value="database" />     

            <property name="eclipselink.jdbc.read-connections.min" value="1" />
            <property name="eclipselink.jdbc.write-connections.min" value="1" />
            <property name="eclipselink.jdbc.batch-writing" value="JDBC" />
            <property name="eclipselink.logging.level" value="SEVERE" />
            <property name="eclipselink.logging.timestamp" value="false" />
            <property name="eclipselink.logging.session" value="false" />
            <property name="eclipselink.logging.thread" value="false" />    
        </properties>
    </persistence-unit>
</persistence>

程序在第二个实例中停止/不继续超出此步骤:

em=factory.createEntityManager();

一步一步调试程序告诉我,此时没有任何反应。也许程序会超时。我已经等了超过 1 分钟了....

你有什么线索可能导致这个失速吗?

【问题讨论】:

    标签: java eclipse eclipse-rcp rcp eclipselink


    【解决方案1】:

    在调试器中,停止所有线程(选择应用程序并单击暂停按钮),然后检查在Object.wait() 中挂起的线程。其中之一必须与您的问题有关。检查 EclipseLink 实例的堆栈跟踪以找出哪个实例。这可能会给你一个线索。

    【讨论】:

    • 我不确定,但在我看来它挂在 jre6\lib\rt.jar 中(没有可用的源)。 “this”的值为 SocketInputStream。所以网络套接字有问题......(我猜)但它不应该抛出异常而不是挂起吗?我该如何继续?
    • 这意味着它等待数据库服务器响应。在流中进一步查看它在等待什么:登录?它是否发送了一些 SQL 并等待执行?也许您的数据库只允许您登录一次。
    猜你喜欢
    • 2012-11-26
    • 2015-04-22
    • 2013-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-29
    • 2011-04-30
    相关资源
    最近更新 更多