activemq-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chris Pettitt (JIRA)" <>
Subject [jira] Created: (AMQ-1956) NPE during broker shutdown when useDatabaseLock="false"
Date Fri, 26 Sep 2008 17:38:52 GMT
NPE during broker shutdown when useDatabaseLock="false"

                 Key: AMQ-1956
             Project: ActiveMQ
          Issue Type: Bug
          Components: Message Store
    Affects Versions: 5.1.0
            Reporter: Chris Pettitt


1. Create a broker with the persistence adapter set to not use database locking (useDatabaseLock="false")
2. Start broker
3. Stop broker (but keep the process running, as in a servlet container)


In the logs, I see the following error every 30 seconds:

2008/09/25 15:23:55.506 INFO [] No longer
able to keep the exclusive lock so giving up being a master
2008/09/25 15:23:55.506 WARN [] Failed
to stop broker
2008/09/25 15:24:25.504 ERROR [] Failed
to update database lock: java.lang.NullPointerException
        at java.util.concurrent.Executors$
        at java.util.concurrent.FutureTask$Sync.innerRunAndReset(
        at java.util.concurrent.FutureTask.runAndReset(
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$101(
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.runPeriodic(
        at java.util.concurrent.ScheduledThreadPoolExecutor$
        at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(
        at java.util.concurrent.ThreadPoolExecutor$


During startup, JDBCPersistenceAdapter only initializes the database locker if useDatabaseLock
if true. This is done through lazy initialization by calling getDatabaseLocker (at ~ line

        if (isUseDatabaseLock()) {
            DatabaseLocker service = getDatabaseLocker();
            if (service == null) {
                LOG.warn("No databaseLocker configured for the JDBC Persistence Adapter");
            } else {

During shutdown, JDBCPersistenceAdapter calls getDatabaseLocker() to shut it down, but it
does not check if isUseDatabaseLock() is true in this case:

    public synchronized void stop() throws Exception {
        if (clockTicket != null) {
            clockTicket = null;
        if (clockDaemon != null) {
            clockDaemon = null;
        DatabaseLocker service = getDatabaseLocker();
        if (service != null) {

This actually causes database locker to be initialized and it subsequently lazy-initializes
an executor to run a task which calls keepAlive(...). The executor threads are set as daemon
threads which prevents this issue from showing up when the lifetime of the process is the
same as the broker. When the broker is deployed in an app server which can outlive the broker
then the above error is logged every 30 seconds.

I'm attaching one way to solve this problem without having to check everywhere if useDatabaseLock="false".

Attached: - sample program that reproduces this bug - sample extension to JDBCPersistenceAdapter that fixes
this bug

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message