在 Java 中获取 Socket 读取超时异常的原因是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/39831250/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-03 04:40:47  来源:igfitidea点击:

What are the reasons for getting a Socket read timed out Exception in Java?

javadatabasesocketssocket.iosocket-timeout-exception

提问by Rishi Rahiman

What are the reasons for getting a Socket read timed out Exception in Java?

在 Java 中获取 Socket 读取超时异常的原因是什么?

I'm gettting:

我得到:

    ### Cause: java.sql.SQLRecoverableException: IO Error: Socket read timed out
; SQL []; IO Error: Socket read timed out; nested exception is java.sql.SQLRecoverableException: IO Error: Socket read timed out

回答by Peter Lawrey

A timeout was set by the library and yet it didn't read anything before the timeout was reached.

库设置了超时,但在达到超时之前它没有读取任何内容。

This could happen if the other end it is reading from stop for a long time. The library determines what counts as a long time. I would look for any errors logged on the server it is connected to.

如果另一端从停止读取很长时间,就会发生这种情况。图书馆决定什么算作长时间。我会查找它所连接的服务器上记录的任何错误。

回答by GhostCat

Depending on your environment, there can be many different reasons: it could be a simple network outage between your machine and the database server. But it could also be that there is a congestion on a lower level; and one layer just sits there; all connection threads taken; waiting for some other side to move ... that won't move any more.

根据您的环境,可能有许多不同的原因:这可能是您的机器和数据库服务器之间的简单网络中断。但也可能是较低级别的拥堵;一层就在那里;采取的所有连接线程;等待另一边移动……那将不再移动。

In that sense, the unspecific answer to your unspecific question is: identify the different components that exist in your system and that need to communicate with each other in order to deliver the functionality that they are supposed to deliver. When you have that "map"; you start checking each location on that map by its own.

从这个意义上说,对您的非特定问题的非特定答案是:确定系统中存在的不同组件,这些组件需要相互通信以提供它们应该提供的功能。当你有那个“地图”时;您开始自行检查该地图上的每个位置。

And hint: if you don't have such a (mental) map yet; well, welcome to the world of professional IT. When you are responsible for a complex system; you simply have to understand the different components within that system; and how they interact. And that is not something that stackoverflow can give to you; that is something that youhave to figure yourself.

并提示:如果你还没有这样的(心理)地图;好吧,欢迎来到专业 IT 的世界。当您负责一个复杂的系统时;您只需要了解该系统中的不同组件;以及他们如何互动。这不是 stackoverflow 可以给你的东西;这是必须自己弄清楚的事情。

回答by edwin moses ma

refer http://docs.oracle.com/javase/6/docs/api/java/sql/SQLRecoverableException.html!

参考http://docs.oracle.com/javase/6/docs/api/java/sql/SQLRecoverableException.html

try to check

尝试检查

  • check input parameters in

    Connection con=DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:xe","username","password");

    • check database account Expiry date

    • try to restart the DataBase

    • try to retry connection

    • if still failed try with another Database dsn
  • 检查输入参数

    Connection con=DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:xe","username","password");

    • 检查数据库帐户到期日期

    • 尝试重启数据库

    • 尝试重试连接

    • 如果仍然失败,请尝试使用另一个数据库 dsn