Working on the problem where I have 3 cash counters serving the number of customers. Every counter take 1 sec to process 1 item apart from third counter which takes 2 sec to process each item. (e.g. customer A with 5 items on counter one will take 5 seconds to complete), Customer B with 3 items on counter C will take 6 seconds. Every customer has different time of joining the queue.
I used the ScheduledExecutorService
to create number of threads equivalent to cash counters.
ScheduledExecutorService scheduledExecutorService =Executors.newScheduledThreadPool(3);
Now my runnable implementation checks the number of items and runs loops accordingly.
I am submitting the number of task depending on number of customer.
scheduledExecutorService.schedule(new Runnable(),Timetojoin, TimeUnit.SECONDS);
How do I assign different priorities to 3 threads created by executor service. As my last counter(thread) takes 2 second to process each item.
You will have to provide custom
ThreadFactory
to theExecutorService
. YourThreadFactory
will allow you to create new Threads that will suit your needs.ScheduledThreadPoolExecutor(int corePoolSize, ThreadFactory threadFactory)
More info here, in the doc.