prashant-ramcharan / courgette-jvm

Multiprocess | Parallel Cucumber-JVM | Parallelize your Java Cucumber tests on a feature level or on a scenario level.
MIT License
134 stars 39 forks source link

How to kill thread? #377

Closed fatahillahardhi closed 1 year ago

fatahillahardhi commented 1 year ago

How do I stop a specific thread? I have a problem on a real iOS device where I use 2 real devices, sometimes one of the devices becomes stuck when running automation and I have to kill all Appium ports (manual from terminal) to be automatically re-run it again. So far, I only knows how to get thread name with the code:

System.out.println(System.getProperty("courgette.threadId"));
System.out.println(System.getProperty("courgette.threadName"));

But I don't know how to stop a thread. For example, there are 2 threads running:

pool-1-thread-1
pool-1-thread-2

For pool-1-thread-2, it runs normally, but when pool-1-thread-1 freeze/stuck, I want to stop the pool-1-thread-1 to be able to re-run it again.

prashant-ramcharan commented 1 year ago

You will have to kill the Java process that started the thread.

You could use a tool like VisualVM to monitor the processes or just kill it directly from the cmd / terminal.

fatahillahardhi commented 1 year ago

I just found the solution without using VisualVM or kill from cmd/terminal (because the Appium randomly hanging/idle).

I create a new Thread for listening Thread from Courgette, when it's hanging it will be stop the Appium.