Updating the process list
If the application started and showed a list of processes, but never updated that list, it wouldn't be very useful at all. What we then need is a way to update the list periodically, and for that, we'll use a Thread
.
As you may or may not know, a Thread
is roughly a means to run a task in the background (the Javadoc describes it as a thread of execution in a program). A system can be single or multithreaded, depending on the needs and runtime environment of the system. And multithreaded programming is hard to get right. Luckily, our use case here is fairly simple, but we must still exercise caution, or we'll see some really unexpected behavior.
Ordinarily, the advice you would get when creating a Thread
is to implement a Runnable
interface, which you will then pass to the thread's constructor, and that's very good advice, as it makes your class hierarchy much more flexible, since you're not tied to a concrete base class (Runnable
is an interface
). In our case, however...