JDBC 网络适配器无法建立 connection/Connection reset/recv 失败

JDBC The Network Adapter could not establish the connection/Connection reset/recv failed

我目前有一个应用程序 运行ning 需要数据库中的数据才能正常工作。

具体细节如下:

我的问题是我偶尔会收到以下错误消息,这会导致数据丢失或 JDBC 资源完全关闭。

[#|2015-10-22T16:25:42.400+0200|WARNING|glassfish3.1.2|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.allocator|_ThreadID=461;_ThreadName=Thread-2;|RAR5038:Unexpected exception while creating resource for pool jdbc. Exception : javax.resource.spi.ResourceAllocationException: Connection could not be allocated because: I/O-Fehler: The Network Adapter could not establish the connection|#]

其次是

[#|2015-10-22T19:10:47.787+0200|WARNING|glassfish3.1.2|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.pool|_ThreadID=461;_ThreadName=Thread-2;|RAR5035:Unexpected exception while destroying resource from pool jdbc. Exception message: Error while destroying resource :I/O-Fehler: Unrecognized Windows Sockets error: 0: recv failed|#]
[#|2015-10-22T19:10:48.052+0200|WARNING|glassfish3.1.2|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.pool|_ThreadID=461;_ThreadName=Thread-2;|RAR5035:Unexpected exception while destroying resource from pool jdbc. Exception message: Error while destroying resource :I/O-Fehler: Connection reset|#]

其次是

 [#|2015-10-22T19:11:33.287+0200|WARNING|glassfish3.1.2|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource.pool|_ThreadID=461;_ThreadName=Thread-2;|RAR5035:Unexpected exception while destroying resource from pool jdbc. Exception message: Error while destroying resource :I/O-Fehler: Socket read timed out|#]

其次是(从我的 impl 中删除了不相关的部分......)

   #|2015-10-23T16:35:00.087+0200|SEVERE|glassfish3.1.2|javax.enterprise.resource.resourceadapter.com.sun.enterprise.resource|_ThreadID=576;_ThreadName=Thread-2;|RAR5031:System Exception
   javax.resource.spi.LocalTransactionException: Getrennte Verbindung
    at com.sun.gjc.spi.LocalTransactionImpl.rollback(LocalTransactionImpl.java:134)
    at com.sun.enterprise.resource.ConnectorXAResource.rollback(ConnectorXAResource.java:213)
    at com.sun.enterprise.transaction.JavaEETransactionImpl.rollback(JavaEETransactionImpl.java:571)
    at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.rollback(JavaEETransactionManagerSimplified.java:893)
    at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5126)
    at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4915)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:2045)
    at com.sun.ejb.containers.BaseContainer.postInvoke(BaseContainer.java:1994)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandler.invoke(EJBLocalObjectInvocationHandler.java:222)
    at com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate.invoke(EJBLocalObjectInvocationHandlerDelegate.java:88)
    at com.sun.proxy.$Proxy248.loadData(Unknown Source)
       ....
    at sun.reflect.GeneratedMethodAccessor1663.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1052)
    at org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1124)
    at com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5388)
    at com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:619)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
       ....
    at sun.reflect.GeneratedMethodAccessor1559.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:571)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:162)
    at com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundTimeout(SystemInterceptorProxy.java:149)
    at sun.reflect.GeneratedMethodAccessor1563.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:861)
    at com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:800)
    at com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:370)
    at com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5360)
    at com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5348)
    at com.sun.ejb.containers.BaseContainer.callEJBTimeout(BaseContainer.java:4058)
    at com.sun.ejb.containers.EJBTimerService.deliverTimeout(EJBTimerService.java:1832)
    at com.sun.ejb.containers.EJBTimerService.access0(EJBTimerService.java:108)
    at com.sun.ejb.containers.EJBTimerService$TaskExpiredWork.run(EJBTimerService.java:2646)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
   Caused by: java.sql.SQLRecoverableException: Getrennte Verbindung
    at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:3921)
    at com.sun.gjc.spi.LocalTransactionImpl.rollback(LocalTransactionImpl.java:128)
    ... 50 more

我有程序故障安全功能,它会打开一个新事务以避免在我的应用程序中出现 ManagedException,并在失败的情况下重试 3 次。

但这显然不足以保证JDBC连接的稳定性。

这里有什么问题?

这就是我尝试过的方法。

  1. IO Error: The Network Adapter could not establish the connection -> 数据库 运行、URL 正确,防火墙已使用自定义 ping 脚本进行测试
  2. java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind (JBOSS) -> 这台电脑是一台 win7 机器,但是参数 -Djava.net.preferIPv4Stack=true 没有帮助
  3. The network adapter could not establish the connection - Oracle 11g -> 用上面列出的新的 jdbc 6 Jar 替换了我原来的 jdbc 6 Jar,没有解决问题
  4. Java JDBC connection status -> 这引起了我的思考

在看到 4 中的 post 之后。我在资源 -> JDBC -> JDBC 连接池 -> jdbc 中尝试了几个配置超时等。我虽然使用

select 1 from SOME_TABLE;

成为解决方案。不幸的是我犯了这样的错误

而不是这个

根据我的理解,不同之处在于第一个在连接进入池时验证连接。第二个在分配给资源使用的池时对其进行验证。

现在似乎工作正常。

希望对您有所帮助!