You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by typedef_lex <co...@chello.at> on 2003/06/04 16:48:20 UTC

JDBCSpoolRepository & lock/unlock

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();
            }
        }
    }

....

RE: JDBCSpoolRepository & lock/unlock

Posted by "Noel J. Bergman" <no...@devtech.com>.
> 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.

What prevents the message from being put back on the list by
loadPendingMessages, if the message is still in the spool?  :-)

    --- Noel


---------------------------------------------------------------------
To unsubscribe, e-mail: james-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: james-dev-help@jakarta.apache.org