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