title: ActiveMQ throws NullPointerException
body: <p>I am using ActiveMQ in my application. Its behaving strangely at some time, when I start the Tomcat server and left it idle for few minutes, I am getting the below exception:</p>
  
  <p><strong>Exception in thread "ActiveMQ Journal Checkpoint Worker" java.lang.NullPointerException
      at org.slf4j.impl.Log4jLoggerAdapter.debug(Log4jLoggerAdapter.java:209)
      at org.apache.activemq.store.kahadb.MessageDatabase.checkpointUpdate(MessageDatabase.java:1349)
      at org.apache.activemq.store.kahadb.MessageDatabase$10.execute(MessageDatabase.java:814)
      at org.apache.kahadb.page.Transaction.execute(Transaction.java:769)
      at org.apache.activemq.store.kahadb.MessageDatabase.checkpointCleanup(MessageDatabase.java:812)
      at org.apache.activemq.store.kahadb.MessageDatabase$3.run(MessageDatabase.java:324)</strong></p>
  
  <p><strong>Exception in thread "ActiveMQ Broker[localhost] Scheduler" java.lang.NullPointerException
      at org.slf4j.impl.Log4jLoggerAdapter.isDebugEnabled(Log4jLoggerAdapter.java:199)
      at org.apache.activemq.broker.region.Queue.expireMessages(Queue.java:816)
      at org.apache.activemq.broker.region.Queue.access$100(Queue.java:96)
      at org.apache.activemq.broker.region.Queue$2.run(Queue.java:136)
      at org.apache.activemq.thread.SchedulerTimerTask.run(SchedulerTimerTask.java:33)
      at java.util.TimerThread.mainLoop(Timer.java:512)
      at java.util.TimerThread.run(Timer.java:462)</strong></p>
  
  <p>After this when the queue is called again, it throws the exception:</p>
  
  <p><strong>Caught: Could not create Transport. Reason: javax.management.InstanceAlreadyExistsException: org.apache.activemq:BrokerName=localhost,Type=Broker
  javax.jms.JMSException: Could not create Transport. Reason: javax.management.InstanceAlreadyExistsException: org.apache.activemq:BrokerName=localhost,Type=Broker</strong></p>
  
  <p>I have used queue producer and consumer as shown below:</p>
  
  <p>Producer:</p>
  
  <pre><code>ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                  "vm://localhost");
  
          // Create a Connection
          Connection connection = connectionFactory.createConnection();
          connection.start();
  
          // Create a Session
          Session session = connection.createSession(false,
                  Session.AUTO_ACKNOWLEDGE);
  
          // Create the destination (Topic or Queue)
          Destination destination = session.createQueue(queuename);
  
          // Create a MessageProducer from the Session to the Topic or Queue
          MessageProducer producer = session.createProducer(destination);
          producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
  
          // Create a messages
          Iterator it = mapMessage.entrySet().iterator();
          MapMessage message = session.createMapMessage();
          while (it.hasNext()) {
              Map.Entry pairs = (Map.Entry)it.next();
              message.setString(""+pairs.getKey(), ""+pairs.getValue());
              System.out.println(pairs.getKey() + " = " + pairs.getValue());
              it.remove(); // avoids a ConcurrentModificationException
          }
  
          // Tell the producer to send the message
          System.out.println("Sent message: "+ message);
          producer.send(message);
  
          // Clean up
          session.close();
          connection.close();
  </code></pre>
  
  <p>Consumer:</p>
  
  <pre><code>ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
                  "vm://localhost");
  
          // Create a Connection
          Connection connection = connectionFactory.createConnection();
          connection.start();
  
          // Create a Session
          Session session = connection.createSession(false,
                  Session.AUTO_ACKNOWLEDGE);
  
          // Create the destination (Topic or Queue)
          Destination destination = session.createQueue("register");
  
          // Create a MessageConsumer from the Session to the Topic or Queue
          MessageConsumer consumer = session.createConsumer(destination);
          consumer.setMessageListener(this);
  </code></pre>
  
  <p>ActiveMQ Integration:</p>
  
  <pre><code>PushRegisterConsumer prc = new PushRegisterConsumer();
      prc.start();
  
  PushQueueProducer pmp = new PushQueueProducer();
  pmp.queueProducer(AppConstants.QUEUE_NAME,registerDetails);
  </code></pre>
  
  <p>The producer and consumer has been integrated as shown above</p>
  
  <p>Please help me resolving this issue.</p>
  
  <p>Thanks,</p>
  
  <p>Karthikeyan</p>