JDBC网络适配器无法建立连接/连接重置/ recv失败

时间:2015-11-17 13:48:02

标签: java oracle jdbc glassfish timeout

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

以下是具体细节:

  • Glassfish 3.1.2
  • Oracle DB 11.2.0.2.0(我在这里访问受限)
  • Java 7 / JEE6
  • JDBC Lib oracle-jdbc-11.2.0.3-jdk6.jar
  • 我在创建新连接池时使用Glassfish的标准配置池
  • 使用的SQL只是在
  • 中没有连接或其他复杂结构的选择
  • 根据SQL
  • ,它们可以在30秒及以下的时间内轻松运行

我的问题是我偶尔会收到以下错误消息,导致数据丢失或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.access$100(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,并在发生故障时重试三次。

然而,这显然不足以确保JDBC连接的稳定性。

这里有什么问题?

1 个答案:

答案 0 :(得分:3)

所以这就是我尝试和工作过的。

  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替换为上面列出的新jar,没有解决问题
  4. Java JDBC connection status - >这让我的想法
  5. 看到4中的帖子后,我在参考资料中尝试了几种配置 - > JDBC - > JDBC连接池 - > jdbc for timeouts等我虽然使用

    select 1 from SOME_TABLE;
    

    是解决方案。不幸的是我犯了错误就像这样使用它

    Wrong configuration

    而不是这个

    Right configuration

    根据我的理解,差异是第一个验证连接进入池时的连接。第二个是在它给出资源使用的池时验证它。

    现在似乎工作正常。

    我希望这有帮助!