title: How to stop the execution of the method in the thread in Java?
body: <p>I have J2EE project which uses framework struts2 and Tomcat. There are two actions: "start task" and "stop task". As I understand it, when a user runs the task "start task", then Tomcat starts a thread where the task is executed. The user can click "stop task" and then Tomcat starts the second thread where it needs to stop the first thread. Method of action where execute task very big. There are queries to DB and calculations. In order to stop thread I use <code>interrupt()</code> of first thread but <code>interrupt()</code> just change value of flag but the code in the method continues to run. I check interrupt flag (<code>Thread.currentThread().isInterrupted()</code>) in different parts of method and if thread is interrupted then I use "return". Is there any other way?</p>