0

在 glassfish(3.1.2) 中,我创建了一个连接到远程 MySql 数据库的 JDBC 连接池(和 JDBC 资源)。在 glassfish 中进行 ping 测试时,它是成功的。

我的 Java EE 6 应用程序正在使用该持久性单元(persistence.xml):

<persistence-unit name="remotePU" transaction-type="JTA">
    <jta-data-source>jdbc/remotePU</jta-data-source>
    <properties> 
    </properties>
</persistence-unit>

在一个 dao 中,我注入了一个持久性上下文:

@PersistenceContext(unitName = "remotePU")
private EntityManager em;

然后我就用这个实体管理器来查询。

我还使用本地数据库测试了相同的设置,并且效果很好,所以我知道错误不在代码中。

我查询时得到的异常堆栈是:

Internal Exception: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
....
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.
....
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
....
Caused by: java.io.EOFException: Can not read response from server. Expected to read 4 bytes, read 0 bytes before connection was unexpectedly lost.

远程连接只是慢吗?这是对远程数据库服务器的 ping:

Pinging xxxxx.net [xx.xx.xx.xx] with 32 bytes of data:
Reply from xx.xx.xx.xx: bytes=32 time=29ms TTL=54
Reply from xx.xx.xx.xx: bytes=32 time=28ms TTL=54
Reply from xx.xx.xx.xx: bytes=32 time=28ms TTL=54
Reply from xx.xx.xx.xx: bytes=32 time=28ms TTL=54

Ping statistics for xx.xx.xx.xx:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 28ms, Maximum = 29ms, Average = 28ms

我可以调整 Glassfish 中的一些 JDBC 连接池设置以获得更好的连接吗?

4

0 回答 0