简体   繁体   English

终止服务时关闭ScheduledExecutorService

[英]Shutdown ScheduledExecutorService when killing service

I have used ScheduledExecutorService for my jar file and i'm executing it as a service in linux machine. 我已将ScheduledExecutorService用于我的jar文件,并将其作为Linux计算机中的服务执行。 I'm stating service by nohup command and killing it with kill command. 我通过nohup命令说明服务,并使用kill命令将其kill But i heard ScheduledExecutorService should be shut down when finishing use it. 但是我听说ScheduledExecutorService在完成使用后应该关闭。 If not, it will keep the JVM running, even when all other threads have been shut down. 如果没有,即使所有其他线程都已关闭,它也将保持JVM运行。

  1. what happen to my ScheduledExecutorService thread when i kill the service? 当我终止服务时,我的ScheduledExecutorService线程会怎样?
  2. if ScheduledExecutorService thread is not shutdown when killing service, how i shut it down ? 如果在关闭服务时ScheduledExecutorService线程未关闭,我如何将其关闭?

If you kill the entire process externally then it will kill the ScheduledExecutorService at the same time since it runs inside the process. 如果从外部终止整个进程,则它将同时终止ScheduledExecutorService ,因为它在进程内部运行。

This is not recommended though as it will kill your program in the middle of whatever processing it's doing. 但是不建议这样做,因为它会在执行任何处理的过程中杀死您的程序。 You might have partially written files for example. 例如,您可能有部分写入的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM