O'Reilly logo

Java 9 Concurrency Cookbook - Second Edition by Javier Fernández González

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

Converting a regular executor into a priority-based executor is simple. You only have to pass a PriorityBlockingQueue object, parameterized by the Runnable interface, as a parameter. But with the executor, you should know that all the objects stored in a priority queue have to implement the Comparable interface.

You implemented the MyPriorityTask class that implements the Runnable interface, which will act as a task, and the Comparable interface to be stored in the priority queue. This class has a Priority attribute that is used to store the priority of the tasks. If a task has a higher value for this attribute, it will be executed earlier. The compareTo() method determines the order of the tasks in the priority queue. In ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required