Concurrency improvements

The ability to employ multiple threads in our Java applications stands to greatly improve efficiency and leverage the increasing processing capabilities of modern computers. The use of threads in Java gives us great granularity in our concurrency controls.

Threads are at the core of Java's concurrency functionality. We can create a thread in Java by defining a run method and instantiating a Thread object. There are two methods of accomplishing this set of tasks. Our first option is to extend the Thread class and override the Thread.run method. Here is an example of that approach:

    . . .    class PacktThread extends Thread    {      . . .      public void run()      {        . . .       }    }    . . .     Thread varT = new PacktThread();    . . . // This next ...

Get Java 9: Building Robust Modular Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.