--- projects/cms/source/util/uk/org/iscream/cms/util/Queue.java 2001/03/22 18:23:27 1.19 +++ projects/cms/source/util/uk/org/iscream/cms/util/Queue.java 2001/05/29 17:02:35 1.22 @@ -1,11 +1,11 @@ //---PACKAGE DECLARATION--- -package uk.org.iscream.util; +package uk.org.iscream.cms.server.util; //---IMPORTS--- import java.util.LinkedList; import java.util.NoSuchElementException; import java.util.Random; -import uk.org.iscream.util.*; +import uk.org.iscream.cms.server.util.*; /** * A Queue class designed to operate in a multi-threaded environment, with @@ -14,7 +14,7 @@ import uk.org.iscream.util.*; * actually contains some elements. * * @author $Author: tdb $ - * @version $Id: Queue.java,v 1.19 2001/03/22 18:23:27 tdb Exp $ + * @version $Id: Queue.java,v 1.22 2001/05/29 17:02:35 tdb Exp $ */ public class Queue { @@ -23,7 +23,7 @@ public class Queue { /** * The current CVS revision of this class */ - public static final String REVISION = "$Revision: 1.19 $"; + public static final String REVISION = "$Revision: 1.22 $"; /** * Pass to constructor to remove a RANDOM item from @@ -94,26 +94,26 @@ public class Queue { for(int i=0; i < _lists.size(); i++) { // skip over any gaps left in the list if(_lists.get(i) != null) { - // get size before adding to the Queue - int s = ((LinkedList) _lists.get(i)).size(); - // check whether we need to remove an item from the current Queue - if(_maxSize!=-1 && s==_maxSize && _removeAlgorithm!=DROP) { - // we need to remove an item - removeQueueItem((LinkedList) _lists.get(i)); - } - // check if we should add (not if Queue full, and using DROP algorithm) - if(!(s==_maxSize && _removeAlgorithm==DROP)) { - // add the next item, ensuring we lock - synchronized(this) { - // LinkedList.add() does the same thing, but this ensures behaviour - ((LinkedList) _lists.get(i)).addLast(o); + synchronized(((LinkedList) _lists.get(i))) { + // get size before adding to the Queue + int s = ((LinkedList) _lists.get(i)).size(); + // check whether we need to remove an item from the current Queue + if(_maxSize!=-1 && s>=_maxSize && _removeAlgorithm!=DROP) { + // we need to remove an item + removeQueueItem((LinkedList) _lists.get(i)); } - } - // if the queue was empty before the add it is possible - // that a consumer is waiting... so we notify them - if (s == 0) { - synchronized(((LinkedList) _lists.get(i))) { - ((LinkedList) _lists.get(i)).notifyAll(); + // check if we should add (not if Queue full, and using DROP algorithm) + if(!(s>=_maxSize && _removeAlgorithm==DROP)) { + // add the next item, ensuring we lock + synchronized(this) { + // LinkedList.add() does the same thing, but this ensures behaviour + ((LinkedList) _lists.get(i)).addLast(o); + } + // if the queue was empty before the add it is possible + // that a consumer is waiting... so we notify them + //synchronized(((LinkedList) _lists.get(i))) { + ((LinkedList) _lists.get(i)).notifyAll(); + //} } } } @@ -332,7 +332,7 @@ public class Queue { * Overrides the {@link java.lang.Object#toString() Object.toString()} * method to provide clean logging (every class should have this). * - * This uses the uk.org.iscream.util.FormatName class + * This uses the uk.org.iscream.cms.server.util.FormatName class * to format the toString() * * @return the name of this class and its CVS revision.