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 to do it...

Follow these steps to implement the example:

  1. Create a class named MyPriorityTask that implements the Runnable and Comparable interfaces parameterized by the MyPriorityTask class interface:
        public class MyPriorityTask implements Runnable,                              Comparable<MyPriorityTask> {
  1. Declare a private int attribute named priority:
        private int priority;
  1. Declare a private String attribute called name:
        private String name;
  1. Implement the constructor of the class to initialize its attributes:
        public MyPriorityTask(String name, int priority) {           this.name=name;           this.priority=priority;         }
  1. Implement a method to return the value of the priority attribute:
        public int getPriority(){           return priority;         }
  1. Implement the compareTo()

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