multithreading - Does Java have an indexable multi-queue thread pool? -


is there java class such that:

  1. executable tasks can added via id, tasks same id guaranteed never run concurrently
  2. the number of threads can limited fixed amount

a naive solution of map solve (1), difficult manage (2). similarly, thread pooling classes know of pull single queue, meaning (1) not guaranteed.

solutions involving external libraries welcome.

if don't find out of box, shouldn't hard roll own. 1 thing wrap each task in simple class reads on queue unique per id, e.g.:

public static class serialcaller<t> implements callable<t> {     private final blockingqueue<caller<t>> delegates;      public serialcaller(blockingqueue<caller<t>> delegates) {         this.delegates = delegates;     }      public t call() throws exception {         return delegates.take().call();     } } 

it should easy maintain map of ids queues submitting tasks. satisfies condition (1), , can simple solutions condition (2), such executors. newfixedthreadpool


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

VBA function to include CDATA -