java.sql.SQLException:Io exception:Socket read timed out vs Closed Connection

时间:2022-09-20 22:53:13

I am trying to research this issue on the following two errors connecting to Oracle DBs:

我试图在连接到Oracle DB的以下两个错误上研究此问题:

  1. Closed Connection
  2. java.sql.SQLException: Io exception: Socket read timed out
  3. java.sql.SQLException:Io异常:Socket读取超时

My understanding:

  1. Closed Connection : Is occurring either because there was some sort of network disruption or the DB closed the session due to some sort "inactivity"
  2. 封闭连接:发生的原因是由于存在某种类型的网络中断或数据库由于某种“不活动”而关闭了会话

  3. java.sql.SQLException: Io exception: Socket read timed out : This is a case where the connection was made successfully but for some reason the socket/data was empty and eventually it timed-out because no data was available.
  4. java.sql.SQLException:Io异常:套接字读取超时:这是连接成功的情况但由于某种原因,套接字/数据为空并最终超时,因为没有可用的数据。

Is it possible to replicate the above errors in a local Oracle DB env ? What are the steps ?

是否可以在本地Oracle DB环境中复制上述错误?步骤是什么?

I appreciate you taking the time to respond.

感谢您抽出宝贵时间作出回应。

Thanks.

2 个解决方案

#1


1  

Your understanding on closed connection is right. reason for closed connection: External devices such as firewall, network devices, and remote database listeners can force network connections to close after a period of inactivity

您对封闭连接的理解是正确的。关闭连接的原因:外部设备(如防火墙,网络设备和远程数据库侦听器)可能会在一段时间不活动后强制关闭网络连接

ReadTimeOut will happen even on active connections. If a query or procedure is taking lot of time, you will get read time out exception.

即使在活动连接上也会发生ReadTimeOut。如果查询或过程花费了大量时间,您将获得读取超时异常。

  • Closed Connection : Shutdown the database listener when database is running
  • Closed Connection:在数据库运行时关闭数据库侦听器

  • ReadTimedOut : Add sleep in procedure for more than 10 minutes and call that procedure from application
  • ReadTimedOut:在程序中添加睡眠超过10分钟,并从应用程序调用该过程

Replication of Socket read time out error in Oracle DB env:

在Oracle DB环境中复制Socket读取超时错误:

  1. setNetworkTimeout for SQL connection // for example sake, set timeout as 120 seconds
  2. 用于SQL连接的setNetworkTimeout //例如,将超时设置为120秒

  3. Call a database procedure from java and sleep in that procedure for time more than setNetworkTimeout

    从java调用数据库过程并在该过程中休眠超过setNetworkTimeout的时间

    dbms_lock.sleep(125); -- sleeps for 125 seconds
    

Since procedure is not returning with-in 120 seconds due to 125 seconds sleep, java will throw socket read time out in above scenario.

由于125秒休眠,过程不会在120秒内返回,因此java将在上面的场景中抛出套接字读取时间。

#2


0  

I have just started working with the java.sql.* package, but here is what I understand. A closed connection is an error that occurs and the DB session closes, but no error handling is done so that is the end of it. With java.SQException you can manage this error (use a throws clause) and print it out or do other error handling methods.

我刚开始使用java.sql。*包,但这是我理解的。关闭连接是发生的错误并且DB会话关闭,但是没有进行错误处理,因此它就是结束。使用java.SQException,您可以管理此错误(使用throws子句)并将其打印出来或执行其他错误处理方法。

Here is a link from Oracle about Exceptions and how to handle them.

以下是Oracle关于异常的链接以及如何处理它们。

Hope this helps.

希望这可以帮助。

Exceptions in Java.

Java中的例外情况。

#1


1  

Your understanding on closed connection is right. reason for closed connection: External devices such as firewall, network devices, and remote database listeners can force network connections to close after a period of inactivity

您对封闭连接的理解是正确的。关闭连接的原因:外部设备(如防火墙,网络设备和远程数据库侦听器)可能会在一段时间不活动后强制关闭网络连接

ReadTimeOut will happen even on active connections. If a query or procedure is taking lot of time, you will get read time out exception.

即使在活动连接上也会发生ReadTimeOut。如果查询或过程花费了大量时间,您将获得读取超时异常。

  • Closed Connection : Shutdown the database listener when database is running
  • Closed Connection:在数据库运行时关闭数据库侦听器

  • ReadTimedOut : Add sleep in procedure for more than 10 minutes and call that procedure from application
  • ReadTimedOut:在程序中添加睡眠超过10分钟,并从应用程序调用该过程

Replication of Socket read time out error in Oracle DB env:

在Oracle DB环境中复制Socket读取超时错误:

  1. setNetworkTimeout for SQL connection // for example sake, set timeout as 120 seconds
  2. 用于SQL连接的setNetworkTimeout //例如,将超时设置为120秒

  3. Call a database procedure from java and sleep in that procedure for time more than setNetworkTimeout

    从java调用数据库过程并在该过程中休眠超过setNetworkTimeout的时间

    dbms_lock.sleep(125); -- sleeps for 125 seconds
    

Since procedure is not returning with-in 120 seconds due to 125 seconds sleep, java will throw socket read time out in above scenario.

由于125秒休眠,过程不会在120秒内返回,因此java将在上面的场景中抛出套接字读取时间。

#2


0  

I have just started working with the java.sql.* package, but here is what I understand. A closed connection is an error that occurs and the DB session closes, but no error handling is done so that is the end of it. With java.SQException you can manage this error (use a throws clause) and print it out or do other error handling methods.

我刚开始使用java.sql。*包,但这是我理解的。关闭连接是发生的错误并且DB会话关闭,但是没有进行错误处理,因此它就是结束。使用java.SQException,您可以管理此错误(使用throws子句)并将其打印出来或执行其他错误处理方法。

Here is a link from Oracle about Exceptions and how to handle them.

以下是Oracle关于异常的链接以及如何处理它们。

Hope this helps.

希望这可以帮助。

Exceptions in Java.

Java中的例外情况。