james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "typedef_lex" <cog...@chello.at>
Subject JDBCSpoolRepository & lock/unlock
Date Wed, 04 Jun 2003 14:48:20 GMT
Sers,

is the lock and unlock method invocation in JDBCSpoolRepository really needed?
If getNextPendingMessage() in eg accept() is called, the Message is removed from the LinkedList
[=pendingMessages] with .removeFirst(), so another Thread couldn't get this removed Message.

....
    public String accept() {
        while (true) {
            //Loop through until we are either out of pending messages or have a message
            // that we can lock
            PendingMessage next = null;
            while ((next = getNextPendingMessage()) != null) {
                if (lock(next.key)) {
                    return next.key;
                }
            }
            //Nothing to do... sleep!
            try {
                synchronized (this) {
                    //System.err.println("waiting : " + WAIT_LIMIT / 1000 + " in " + repositoryName);
                    wait(WAIT_LIMIT);
                }
            } catch (InterruptedException ignored) {
            }
        }
    }

....

private PendingMessage getNextPendingMessage() {
        //System.err.println("Trying to get next message in " + repositoryName);
        synchronized (pendingMessages) {
            if (pendingMessages.size() == 0 && pendingMessagesLoadTime < System.currentTimeMillis())
{
                pendingMessagesLoadTime = LOAD_TIME_MININUM + System.currentTimeMillis();
                loadPendingMessages();
            }

            if (pendingMessages.size() == 0) {
                return null;
            } else {
                //System.err.println("Returning a pending message in " + repositoryName);
                return (PendingMessage)pendingMessages.removeFirst();
            }
        }
    }

....

Mime
View raw message