Java Executor, add new tasks at the bottom / end of the queue

324 views Asked by At

I want to have an Executor with the possibility to choose whether new task is added at the top or at the bottom of the queue. What is the simplest way to achieve that?

1

There are 1 answers

0
AlexR On

I think that you can achieve this functionality by using PriorityQeueue (or PriorityBlockingQueue depending on your needs).

These queues process tasks in order that depends on Comparator. Although this comparator is passed to the queue when it is created you can implement your custom comparator that has its own logic that can decide whether specific task is lower or higher priority.