当我在后台运行 Java 进程并关闭计算机 (ArchLinux) 时,计算机会等待几秒钟以终止我在 Java 中的关闭 Hook 吗?
最佳答案
如果你想在系统关闭时做一些事情,你需要添加一个关闭 Hook (假设你已经这样做了):
Runtime.getRuntime().addShutdownHook(
new Thread(new Runnable() {
@Override
public void run() {
// This method will be executed and Virtual Machine will close when this method will return
}
}));
如果花费太多时间,系统将永远等待完全终止
When the virtual machine is terminated due to user logoff or system shutdown the underlying operating system may only allow a fixed amount of time in which to shut down and exit. It is therefore inadvisable to attempt any user interaction or to perform a long-running computation in a shutdown hook.
关于java - Linux 关机和 Java 关机 Hook ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41210466/