[concurrency-interest] Task Queue ordering

Ken--@newsgroupstats.hk dragonken at gmail.com
Sat Dec 5 00:51:23 EST 2009


Dear Joe,

Sorry I cannot under how to achieve it. I have tasks to be submitted in
order (task1 to task6) like this:

public class SerialTask implements Runnable {
    private String client = null;
    private long sleep = 0;
    public SerialTask(String client, long sleep){
        this.client = client;
        this.sleep = sleep;
    }
    public void run() {
        try {Thread.sleep(sleep);} catch (Exception e) {}
        String msg = "Task ID = " + client + ", sleep = " + sleep;
        System.out.println(msg);
    }
}

SerialTask task1 = new SerialTask("client-a", 10);
SerialTask task2 = new SerialTask("client-a", 10);
SerialTask task3 = new SerialTask("client-a", 10);
SerialTask task4 = new SerialTask("client-b", 2000);
SerialTask task5 = new SerialTask("client-b", 4000);
SerialTask task6 = new SerialTask("client-a", 10);

How can I make use of SerialExecutor to execute client's task in order? I
expected client-a's tasks can be finished in 40 mills and tasks are run in
serial. and after around (2000 + 4000 - 40) mills, all client-b tasks are
finished. 

Regards,
Ken




Joe Bowbeer wrote:
> 
> If each client's tasks are executed sequentially, you can use a
> SerialExecutor per client.  See the "SerialExecutor" example in the
> Executor
> javadoc.  Each client's executor would delegate to the shared thread pool
> executor.
> 
> If all tasks can execute in concurrently, but you want to retire them in
> order, I think there was a useful discussion about this in June '08.
> Search for "Out-of-order execution, in-order retirement".
> 
> (The suggestion was to queue the Futures when the Callables are submitted,
> and retire the tasks in the order they were enqueued.)
> 
> --Joe
> 
> On Wed, Dec 2, 2009 at 6:32 PM, Ken-- at newsgroupstats.hk wrote:
> 
>>
>> Hi All,
>>
>> I have a Task Queue (ArrayBlockingQueue) with single thread for client's
>> task processing. For same client, I  have to guarantee the ordering of
>> task
>> results as I need the result of previous task to perform next task of the
>> same client. It's work for ArrayBlockQueue with single thread as it's
>> always
>> FIFO.
>>
>> My question is, how to enable multi threads (like ThreadPoolExecutor) for
>> queue but maintaining the ordering of same client's tasks? I tried
>> PriorityBlockingQueue but it just ensure tasks are started in order.
>>
>> Any solution? Please help.
>>
>> Thanks and Best Regards,
>> Ken
>>
>>
> 
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> 
> 

-- 
View this message in context: http://old.nabble.com/Task-Queue-ordering-tp26585945p26653201.html
Sent from the JSR166 Concurrency mailing list archive at Nabble.com.



More information about the Concurrency-interest mailing list