Home > Back-end >  Made the task of timing ScheduledExecutorService problem
Made the task of timing ScheduledExecutorService problem

Time:12-15

Would you like to do a statistical function of user data, need time trigger, ScheduledExecutorService,
 public class Scheduled_Job {
Public static void main (String [] args) {
A Runnable Runnable=new Runnable () {
Public void the run () {
Mobile_Count. Count_mobile ();
}
};

ScheduledExecutorService service=Executors. NewSingleThreadScheduledExecutor ();
Service. ScheduleAtFixedRate (runnable, 10, 10, TimeUnit. SECONDS);
}
}


After the Eclipse was implemented, can see effect, but the job after turn off the Eclipse has stopped, does that mean that as long as the entry method main destroyed, this schedule also can't go on? What if I want to run on the server, some way?

CodePudding user response:

As long as there is not a daemon thread 1 is the JVM will not exit will make the main sleep don't quit
  • Related