16.4. Creating a Multithreaded Method

Occasionally, you will realize, after the fact, that some of the code that you wrote just begs to be threaded. Often this occurs because the program moved from a single- user environment to a multiuser environment. Here, processing each user serially is no longer acceptable. Or, another possibility is that your program invokes a computation-intensive method, leaving the user to simply wait until the process has completed before continuing. Not pretty.

In many cases, you can create a new class that runs the designated task in the background without modifying the original class at all. Conceptually, the idea is to inherit from the original class, make the class Runnable, and override the original method to ...

Get Core Web Programming, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.