Java J2EE Spring Chapter 5: Stopping a Thread

When you want a thread to terminate or stop based on some condition, you have several approaches available. For ex, you may want to terminate a thread because it has completed the intended operation or because the user clicked the exit button. Though there are many approaches to do it, we are going to take a look at the two most common ways of doing it.

1. Setting a Flag

The most common way of