I searched a lot, but did not find any solution. I use java thread pool in this way:
ExecutorService c = Executors.newFixedThreadPool(3); for (int i = 0; i < 10; ++i) { c.execute(new MyTask(i)); }
Thus, tasks are performed in sequential order (as in the queue). But I need to change the strategy of "choose the next task." Therefore, I want to assign each task a priority (this is not a priority of the thread), and the execution of tasks corresponds to these priorities. Therefore, when the executor has finished another task, he selects the next task as the task with the highest priority. He describes a general problem. Perhaps there is a simpler approach that does not take priorities into account. He selects the last task added as the next to be executed instead of the first addition. Roughly speaking, FixedThreadPool uses the FIFO strategy. Can I use, for example, the LIFO strategy?
java multithreading threadpool threadpoolexecutor
Rustam Yuzmukhametov Oct 04 2018-12-12T00: 00Z
source share