Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ResultSet.next() hung while talking to oracle 11.2 using jdbc

Tags:

java

oracle

jdbc

We have a java application that talks to oracle 11.2 using jdbc. We are using oracle-jdbc-7.jar

Created-By: 20.12-b01 (Sun Microsystems Inc.)
Implementation-Vendor: Oracle Corporation
Implementation-Title: JDBC
Implementation-Version: 12.1.0.1.0

We are also using Statement.setQueryTimeout()

However, every few days, the thread talking to oracle hangs while doing a ResultSet.next().

Code looks like this:

PreparedStatement ps = createPreparedStatement();
ps.setQueryTimeout(60);

while (true) {
    ps.executeQuery();

    //iterate over the ResultSet doing ResultSet.next() continuously

    //do something with the ResultSet

    //sleep for 1 second.
}

Threaddump:

java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:152)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at oracle.net.ns.Packet.receive(Packet.java:311)
at oracle.net.ns.DataPacket.receive(DataPacket.java:105)
at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:305)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:249)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:171)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:89)
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123)
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79)
at oracle.jdbc.driver.T4CMAREngineStream.unmarshalUB1(T4CMAREngineStream.java:426)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:390)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:249)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:566)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:215)
at oracle.jdbc.driver.T4CPreparedStatement.fetch(T4CPreparedStatement.java:1022)
at oracle.jdbc.driver.OracleStatement.fetchMoreRows(OracleStatement.java:3590)
at oracle.jdbc.driver.InsensitiveScrollableResultSet.fetchMoreRows(InsensitiveScrollableResultSet.java:1008)
at oracle.jdbc.driver.InsensitiveScrollableResultSet.absoluteInternal(InsensitiveScrollableResultSet.java:972)
at oracle.jdbc.driver.InsensitiveScrollableResultSet.next(InsensitiveScrollableResultSet.java:572)
- locked <0x00000000d0873738> (a oracle.jdbc.driver.T4CConnection)

Any ideas on resolving this would be appreciated?

We have tried using openjdk7 and oracle's JDK 7 but it did not help.

Thanks.

like image 234
Vikas Gupta Avatar asked Jul 28 '15 23:07

Vikas Gupta


People also ask

What is ResultSet next ()?

The next() method of the ResultSet interface moves the pointer of the current (ResultSet) object to the next row, from the current position. Statement stmt = con. createStatement(); ResultSet rs = stmt.

What is the function of RS next () in a ResultSet called RS?

As to the concrete question about rs. next() , it shifts the cursor to the next row of the result set from the database and returns true if there is any row, otherwise false .

What is the default type of ResultSet in JDBC applications?

The default ResultSet type is TYPE_FORWARD_ONLY .

How do I set the fetch size in JDBC?

To set the fetch size for a query, call setFetchSize on the statement object prior to running the query. If you set the fetch size to N, then N rows are fetched with each trip to the database.


1 Answers

Try to find the blocking session.

SELECT
   s.blocking_session, 
   s.sid, 
   s.serial#, 
   s.seconds_in_wait
FROM
   v$session s
WHERE
   blocking_session IS NOT NULL

If it is your session, then your query might need optimization. Otherwise something else is causing the issue.

P.S. : I am no SQL expert

like image 79
systemhalted Avatar answered Nov 15 '22 00:11

systemhalted