Is this consumer code OK? Sometimes I got OutOfMemoryException and I can't find 
what resources I am not releasing...

while (true) {
  try {
    Connection conn = oraPC.getConnection();
    Statement stmt = null;
    try {
      while ((message = mq_consumer.receive(10)) != null) {
        if (message instanceof ObjectMessage) {
          if (stmt == null)
            stmt = conn.createStatement();
            ObjectMessage msg = (ObjectMessage)message;
            String insert = getInsert(msg);
            stmt.addBatch(insert);
            sql += "\r\n"+insert;
          }
        }
        if (stmt != null) {
          stmt.executeBatch();
          conn.commit();
          mq_session.commit();
        }
      }
    } finally {
      if (stmt != null)
      try {
        stmt.close();
        stmt = null;
      } catch (SQLException e) {}
        if (conn != null)
        try {
          conn.close();
          conn = null;
        } catch (SQLException e) {}
      }
    } catch (Exception e) {
      e.printStackTrace();
      try { mq_session.rollback(); } catch (JMSException e1) { 
e1.printStackTrace(); }
    }
    // Sleep here...
}

And this is how I init MQ session:

mq_session = mq_connection.createSession(true, Session.AUTO_ACKNOWLEDGE);



      

Reply via email to