I've searched a lot but couldn't find any solution. I use java thread pool in such way:
ExecutorService c = Executors.newFixedThreadPool(3);
for (int i = 0; i < 10; ++i) {
c.execute(new MyTask(i));
}
In such way Tasks are executed in consequent order (as in queue). But I need change "select next task" strategy. So I want assign to each task specify priority (it isn't thread priority) and execute tasks correspond to these priorities. So when executor have finished another task it chooses next task as task with maximum priority. It describes common problem. Maybe there is more simple approach which doesn't account priorities. It selects last added task as next to execute instead of first added. Roughly speaking FixedThreadPool use FIFO strategy. Can I use for example LIFO strategy?
See Question&Answers more detail:os