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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access