转自https://www.chenx.tech/priority-blocking-queue/
简单来说,方案一:
public class Task implements Runnable, Comparable<Task>
加
ThreadPoolExecutor executor = new ThreadPoolExecutor(..., new PriorityBlockingQueue<>(), ...);
executor.execute(task);
方案二:
方案一中的Task 加上:
public class ComparableFutureTask extends FutureTask<Object> implements Comparable<ComparableFutureTask>
加
ThreadPoolExecutor executor = new ThreadPoolExecutor(..., new PriorityBlockingQueue<>(), ...);
executor.execute(new ComparableFutureTask(task));