Java threads remaining locked forever when attempting to insert into Oracle DB
We've a Java application which periodically insert rows into the Oracle DB. This is a multi-threaded application. All threads barring one gets stuck periodically. We're thinking of upgrading the Oracle JDBC Driver, but I've a feeling it might show up again. Just wanted to get some info on if its an error with our code or something else. I've both the stacktrace and the parts of code below. We see locked periodically in the thread info. Do give us some info as to what could me wrong.

----Code----

LogEventBatchPreparedStatementUpdater statementUpdater = new LogEventBatchPreparedStatementUpdater(logEvents);

//        _jdbcTemplate.batchUpdate(INSERT_SQL, statementUpdater);
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        try
        {
            connection = _dataSource.getConnection();
            connection.setAutoCommit(false);
            preparedStatement = connection.prepareStatement(INSERT_SQL);
            for (int i = 0; i < statementUpdater.getBatchSize(); i++)
            {
                statementUpdater.setValues(preparedStatement, i);
                preparedStatement.addBatch();
            }
            preparedStatement.executeBatch();
            connection.commit();
        }
        catch (SQLException e)
        {
            _Log.error("Error inserting log line batch",e );
        }
        finally
        {
            try
            {
                preparedStatement.close();
                connection.close();
            }
            catch (SQLException e)
            {
                _Log.error("Error inserting log line batch",e );
            }
        }


----Stack Trace----

"Thread-258 " daemon prio=6 tid=0x09437400 nid=0x2300 runnable [0x0f55f000]
   java.lang.Thread.State: RUNNABLE
        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.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.ttc7.MAREngine.unmarshalUB1(MAREngine.java:931)
        at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:893)
        at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:369)
        at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
        at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:109
3)
        - locked <0x1ce417c0> (a oracle.jdbc.ttc7.TTC7Protocol)
        at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.ja
va:2047)
        at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.jav
a:1940)
        at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePrepare
dStatement.java:3899)
        - locked <0x18930c00> (a oracle.jdbc.driver.OraclePreparedStatement)
        - locked <0x1ce3f9f0> (a oracle.jdbc.driver.OracleConnection)
        at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingSt
atement.java:294)
        at ************.insertLogEventBatch(JdbcL
ogEventBatchDao.java:61)
        at ************.DBLogEventBatchProcessor.processLo
gLineBatch(DBLogEventBatchProcessor.java:30)
        at ************.LogLineBatcher.processLogLineBatch
(LogLineBatcher.java:274)
        at ************.LogLineBatcher.processBatchBasedOn
Time(LogLineBatcher.java:192)
        at ************.LogLineBatcher.manageBatch(LogLine
Batcher.java:178)
        at ************.LogLineBatcher.access$000(LogLineB
atcher.java:24)
        at ************.LogLineBatcher$1.run(LogLineBatche
r.java:152)
        at java.lang.Thread.run(Unknown Source)
Java threads remaining locked forever when attempting to insert into Oracle DB
===

We've a Java application which periodically insert rows into the Oracle DB. This is a multi-threaded application. All threads barring one gets stuck periodically. We're thinking of upgrading the Oracle JDBC Driver, but I've a feeling it might show up again. Just wanted to get some info on if its an error with our code or something else. I've both the stacktrace and the parts of code below. We see locked periodically in the thread info. Do give us some info as to what could me wrong.

----Code----

LogEventBatchPreparedStatementUpdater statementUpdater = new LogEventBatchPreparedStatementUpdater(logEvents);

//        _jdbcTemplate.batchUpdate(INSERT_SQL, statementUpdater);
        Connection connection = null;
        PreparedStatement preparedStatement = null;
        try
        {
            connection = _dataSource.getConnection();
            connection.setAutoCommit(false);
            preparedStatement = connection.prepareStatement(INSERT_SQL);
            for (int i = 0; i < statementUpdater.getBatchSize(); i++)
            {
                statementUpdater.setValues(preparedStatement, i);
                preparedStatement.addBatch();
            }
            preparedStatement.executeBatch();
            connection.commit();
        }
        catch (SQLException e)
        {
            _Log.error("Error inserting log line batch",e );
        }
        finally
        {
            try
            {
                preparedStatement.close();
                connection.close();
            }
            catch (SQLException e)
            {
                _Log.error("Error inserting log line batch",e );
            }
        }


----Stack Trace----

"Thread-258 " daemon prio=6 tid=0x09437400 nid=0x2300 runnable [0x0f55f000]
   java.lang.Thread.State: RUNNABLE
        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.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.ttc7.MAREngine.unmarshalUB1(MAREngine.java:931)
        at oracle.jdbc.ttc7.MAREngine.unmarshalSB1(MAREngine.java:893)
        at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:369)
        at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1891)
        at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:109
3)
        - locked <0x1ce417c0> (a oracle.jdbc.ttc7.TTC7Protocol)
        at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.ja
va:2047)
        at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.jav
a:1940)
        at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePrepare
dStatement.java:3899)
        - locked <0x18930c00> (a oracle.jdbc.driver.OraclePreparedStatement)
        - locked <0x1ce3f9f0> (a oracle.jdbc.driver.OracleConnection)
        at org.apache.commons.dbcp.DelegatingStatement.executeBatch(DelegatingSt
atement.java:294)
        at ************.insertLogEventBatch(JdbcL
ogEventBatchDao.java:61)
        at ************.DBLogEventBatchProcessor.processLo
gLineBatch(DBLogEventBatchProcessor.java:30)
        at ************.LogLineBatcher.processLogLineBatch
(LogLineBatcher.java:274)
        at ************.LogLineBatcher.processBatchBasedOn
Time(LogLineBatcher.java:192)
        at ************.LogLineBatcher.manageBatch(LogLine
Batcher.java:178)
        at ************.LogLineBatcher.access$000(LogLineB
atcher.java:24)
        at ************.LogLineBatcher$1.run(LogLineBatche
r.java:152)
        at java.lang.Thread.run(Unknown Source)