在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连接池设置以获得更好的连接吗?