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 Event and specify that it implements the Comparable interface parameterized by the Event class:
        public class Event implements Comparable<Event> {
  1. Declare a private int attribute named thread to store the number of threads that have created the event:
        private final int thread;
  1. Declare a private int attribute named priority to store the priority of the event:
        private final int priority;
  1. Implement the constructor of the class to initialize its attributes:
        public Event(int thread, int priority){           this.thread=thread;           this.priority=priority;         }
  1. Implement the getThread() method to return the value of the thread attribute:
 public int getThread() ...

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