I have a simple Java program running in a Linux box, and the program basically schedules a recurring task that runs for example every hour, so it is kind of like a Daemon thread sitting there but not quite. I am wondering how do know if the program is still running in Linux as well as how to terminate the program running ? Do I need to find a way to trigger the cancel method ? or I can just kill it by using Linux command ? or I need to write a stop and run script ? I am not sure if this could be an open-ended question, but what's the best approach in practice.
Here's my java code
public static void main(String [] args){
ScheduledExecutorService task =
Executors.newSingleThreadScheduledExecutor();
task.scheduleAtFixedRate(new Task(),0,1,TimeUnit.HOURS);
}
static class Task{
@Override
public void run(){
//do something
}
}