1 Reply Latest reply on Jun 5, 2012 11:02 AM by garytully

    Question on implementation of doDeleteOldMessages() in org.apache.activemq.

    mikmela

      I came across the code below in org.apache.activemq.store.jdbc.adapter.DefaultJDBCAdapter.

      As part of  https://issues.apache.org/jira/browse/AMQ-3288  the doDeleteOldMessages() was changed...

      It seems that priorityIterator gets incremented every time doDeleteOldMessages is called which in turn seems to depend on checkpoint interval. This approach looks a bit unusual to me... Yes, even with interval of in 1 sec it will take more  than 68 years to

      get to the point where it silently overflow and start generating negative priority, but if user will by accident set it 1 millisecond it will happened in 24 days... Why would we need a ticking bomb in the code?... Am I missing something? Is the object instance is short-lived that it is not important? 

       

          int priorityIterator = 0;

          public void doDeleteOldMessages(TransactionContext c) throws SQLException, IOException {

              PreparedStatement s = null;

              cleanupExclusiveLock.writeLock().lock();

              try {

                  LOG.debug("Executing SQL: " + this.statements.getDeleteOldMessagesStatementWithPriority());

                  s = c.getConnection().prepareStatement(this.statements.getDeleteOldMessagesStatementWithPriority());

                 int priority = priorityIterator++%10;

                  s.setInt(1, priority);

                  s.setInt(2, priority);

                  int i = s.executeUpdate();

                  LOG.debug("Deleted " + i + " old message(s) at priority: " + priority);

              } finally {

                  cleanupExclusiveLock.writeLock().unlock();

                  close(s);

              }

          }