JDBC hang on Statement 规格严格

On Oct 19, 9:15 am, "Amos B" <amos...> wrote:
> Hi,
> I've run into this issue multiple times with no solution yet.
> For different reasons, the connection between the java application and
> the oracle server may drop. This can happen because the network
> interface was stopped and started or because of a firewall.
>
> The problem is that when the network connection drops for the above
> reasons, the jdbc connections can get stuck while trying to read from a
> socket. These connection hang forever. Highly annoying.
>
> Is there anyway to configure the timeout value of the socket used by
> the JDBC driver?
>
> Here is an example stack trace:
>
> at java.net.SocketInputStream.socketRead0(Native Method)
> at java.net.SocketInputStream.read(Unknown Source)
> at oracle.net.ns.Packet.receive(Unknown Source)
> at oracle.net.ns.DataPacket.receive(Unknown Source)
> at oracle.net.ns.NetInputStream.getNextPacket(Unknown Source)
> at oracle.net.ns.NetInputStream.read(Unknown Source)
> at oracle.net.ns.NetInputStream.read(Unknown Source)
> at oracle.net.ns.NetInputStream.read(Unknown Source)
> at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:971)
> at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:941)
> at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:432)
> at
> oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:1­81)
> at
> oracle.jdbc.driver.T4CPreparedStatement.execute_for_rows(T4CPreparedStateme­nt.java:543)
> at
> oracle.jdbc.driver.OracleStatement.execute_maybe_describe(OracleStatement..j­ava:915)
> at
> oracle.jdbc.driver.T4CPreparedStatement.execute_maybe_describe(T4CPreparedS­tatement.java:452)
> at
> oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.jav­a:986)
> at
> oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedSt­atement.java:2888)
> at
> oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedState­ment.java:2929)
> - locked <0x5b9005d8> (a oracle.jdbc.driver.T4CPreparedStatement)
> - locked <0x5c246760> (a oracle.jdbc.driver.T4CConnection)


Hi. You have some options:

0 - Have you tried calling Statement.setQueryTimeout()?

1 - Alter your OS's TCP timeout so it notifies the socket
sooner than the default TCP timout (usually 5 minutes).

If your thread hangs much longer, then it's a serious firewall
problem, where it keeps the client-side socket open, but
simply stops passing stuff to it or from it...

2 - If you get Oracle's latest driver (10.2) and decompile it to
find some undocumented methods/interfaces. There is an
abort() method on the connection. If you cast your connection
to the right class/interface you can call that method, which
will close the connection/socket without being blocked by
the hanging thread, and you can clear it up that way.

Joe Weinstein at BEA
原文地址:https://www.cnblogs.com/diyunpeng/p/2109437.html