обрабатывать ситуацию блокировки C3po и oracle, когда происходит пакетное обновление - PullRequest
1 голос
/ 30 октября 2019

Иногда мой поток зависал в этом состоянии, я думаю, что есть блокировка соединения с БД, так как я могу решить эту блокировку;этот случай происходит, когда уникальная ошибка ограничения затем вводится в однобайтовый метод для каждой обработки записи

"scheduling-1" - Thread t@38
   java.lang.Thread.State: RUNNABLE
        at java.net.SocketInputStream.socketRead0(Native Method)
        at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
        at java.net.SocketInputStream.read(SocketInputStream.java:171)
        at java.net.SocketInputStream.read(SocketInputStream.java:141)
        at oracle.net.ns.Packet.receive(Packet.java:300)
        at oracle.net.ns.DataPacket.receive(DataPacket.java:106)
        at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:315)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:260)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:185)
        at oracle.net.ns.NetInputStream.read(NetInputStream.java:102)
        at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:124)
        at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:80)
        at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1137)
        at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:290)
        at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
        at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
        at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
        at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1044)
        at oracle.jdbc.driver.OraclePreparedStatement.executeForRowsWithTimeout(OraclePreparedStatement.java:10130)
        at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10249)
        - locked <7026a1d3> (a oracle.jdbc.driver.T4CConnection)
        at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:230)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:2544)
        at org.springframework.jdbc.core.JdbcTemplate.lambda$batchUpdate$2(JdbcTemplate.java:950)
        at org.springframework.jdbc.core.JdbcTemplate$$Lambda$463/1248908034.doInPreparedStatement(Unknown Source)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:646)
        at org.springframework.jdbc.core.JdbcTemplate.batchUpdate(JdbcTemplate.java:936)

настройки c3po

ds.tes.jdbcUrl=jdbc:oracle:thin:AASDAS
ds.tes.driverClass = oracle.jdbc.driver.OracleDriver
ds.tes.username=AA
ds.tes.password=P_AA
ds.tes.maxPoolSize = 550
ds.tes.minPoolSize = 5
ds.tes.initPoolSize = 10
ds.tes.acquireInc = 5
ds.tes.acquireRetryAtt = -1

запрос БД -

 @Override
   public void insertDeliver(List<SrmDeliver> srm) {
      logger.info("insertSrmDeliver - begin "+srm.size());

      getJdbcTemplate().batchUpdate(SRM_DELIVER_SQL, new BatchPreparedStatementSetter() {


         @Override
         public void setValues(PreparedStatement ps, int i) throws SQLException {
            TimeStamp time = new TimeStamp();
            final Calendar date = time.setup(srm.get(i).receiveTime, dateFormat);
            Timestamp timestamp = new Timestamp(date.getTimeInMillis());

            ps.setInt(1, srm.get(i).nodeId);
            setInteger(ps, 2, ( srm.get(i)).service);
            ps.setString(3, ( srm.get(i)).client);
            ps.setString(4, ( srm.get(i)).reportId);
            setInteger(ps, 5, ( srm.get(i)).resultCode);
            ps.setTimestamp(6, timestamp);
         }

         @Override
         public int getBatchSize() {
            return srm.size();
         }
      });

      logger.info("insertSrmDeliver - end "+srm.size());

метод потока

   private boolean insertRows(List<T> chunkList, List<String> dbErrorList) {

      boolean retval = false;
      try {

         insertChunksToDb(chunkList);

         retval = true;

      } catch (Exception e) {
         logger.error(" DB Exception. Hash:" + this.hashCode(), e);
         insertOneByOne(chunkList, dbErrorList);
         return false;

      }

      return retval;
   }

Журнал приложения

Caused by: java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (TIMS.SRM_DISP_PK) violated

        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:445)
        at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:396)
        at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:879)
        at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:450)
        at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:192)
        at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
        at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
        at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1044)
        at oracle.jdbc.driver.OraclePreparedStatement.executeForRowsWithTimeout(OraclePreparedStatement.java:10130)
        at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10249)
        at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:230)
        at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:2544)
        at org.springframework.jdbc.core.JdbcTemplate.lambda$batchUpdate$2(JdbcTemplate.java:950)
        at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:617)
...