getQueue() will always return the exact BlockingQueue<Runnable> that you pass to ThreadPoolExecutor .
The concern with the documentation is that you can easily run into double-launch problems if you cannot guarantee the safety of the BlockingQueue stream. If you use PriorityBlockingQueue and use only remove and add (or, more directly, offer ), then you will be safe, and you can even do it directly from getQueue() .
In other words, whenever your signal tells you that the Runnable priority has been changed, you must remove it and check the result of the deletion ( true if it was deleted), and only if it was deleted, you must re-add it. You do not guarantee that something will not be achieved between these operations, but you will at least be guaranteed that you will not run Runnable twice, which can be easily done if you do this using contains → remove → add .
Either that, or you can write your own implementation of BlockingQueue that uses a Comparator (e.g. PriorityBlockingQueue ) that finds the highest priority when new information is requested. It sounds a lot more considering the various interfaces.
pickypg
source share