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...

In this recipe, you implemented a custom MyThread class extending the Thread class. This class has three attributes to store the creation date, the start date of its execution, and the end date of its execution. Using the start date and end date attributes, you implemented the getExecutionTime() method that returns the total time the thread spent in executing its task. Finally, you overrode the toString() method to generate information about a thread.

Once you had your own thread class, you implemented a factory to create objects of that class by implementing the ThreadFactory interface. It's not mandatory to make use of the interface if you're going to use your factory as an independent object, but if you want to use this ...

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