below is my Thread code. I want to call stopThread() method when I terminates JVM. Please suggest right way to do.
public class Test {
public static void main(String[] args) {
ScheduledExecutorService scheduledExecutor = Executors.newScheduledThreadPool(10);
for(int i=0;i<5;i++){
scheduledExecutor.submit(new MyRunnable())
}
scheduledExecutor.shotdown()
.....
}
public class MyRunnable implements Runnable
{
boolean isRunning = true;
public void run()
{
while(isRunning)
{
Thread.sleep(5000);
}
}
public void stopThread()
{
isRunning = false;
}
}