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