I have a GUI program that runs TestNG automation scripts. This meant that users could easily configure some parameters and run the automatic script they want.
One thing I need to add is the ability to instantly stop the running TestNG process. Something like the βFinishβ button in Eclipse will immediately stop everything that works.
This is what the code that runs the TestNG tests looks like this:
public class ScriptRunner implements Runnable { public void runScript() { Thread testRun = new Thread(this); testRun.start(); } @Override public void run() {
According to the comment, tng.run() may take several minutes, and it performs several actions, opening / closing browser windows, etc.
How can I just terminate the process immediately, for example, when starting an application from the IDE?
EDIT:
In the comments, I am trying to use shutDownNow() and shutDownNow() . The code is as follows:
ExecutorService executorService = Executors.newFixedThreadPool(10); public void runScript() { executorService.execute(this); } //this method gets called when I click the "stop" button public void stopRun() { executorService.shutdownNow(); } @Override public void run() { //same stuff as from earlier code }
source share