org.limewire.collection
Class RRProcessingQueue
java.lang.Object
org.limewire.collection.RRProcessingQueue
public class RRProcessingQueue
- extends Object
Executes Runnables in a round-robin order per queue ID.
class Runner implements Runnable {
final int item;
Runner(int item) {
this.item = item;
}
public void run() {
try {
Thread.sleep(150);
System.out.println("Item: " + item);
} catch (InterruptedException iex) {
System.out.println(iex.toString());
}
}
}
RRProcessingQueue rrpq = new RRProcessingQueue("sampleCodeRRProcessingQueue");
rrpq.execute(new Runner(1), "Abby");
rrpq.execute(new Runner(2), "Bob");
rrpq.execute(new Runner(3), "Abby");
rrpq.execute(new Runner(4), "Bob");
rrpq.execute(new Runner(5), "Chris");
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {}
Output:
Item: 1
Item: 2
Item: 5
Item: 3
Item: 4
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
RRProcessingQueue
public RRProcessingQueue(String name)
execute
public void execute(Runnable runner,
Object queueId)
notifyAndStart
protected void notifyAndStart()
- Notifies the waiting thread or starts a new one.
moreTasks
protected boolean moreTasks()
next
protected Runnable next()
size
public int size()
clear
public void clear()
clear
public void clear(Object name)
Copyright © 2009 Lime Wire LLC. All Rights Reserved.