shutdown-hook

Java -How to get logger to work in shutdown hook?

北慕城南 提交于 2020-06-11 18:16:22
问题 I have a specialized logger class which uses the java.util.logging.Logger class. I want to be able to use this logger in the shutdown hook of another class. However, it doesn't seem to log at shutdown. From what I've read, there may already be a shutdown hook activated for the logger itself which is causing the issue. How can I get this to work? Ideally, I would like it to be seen in the log file that I did in fact execute the shutdown hook when the process terminated. 回答1: Again looking at

PHP's register_shutdown_function to fire when a script is killed from the command line?

为君一笑 提交于 2020-01-21 06:34:06
问题 Is it possible to invoke a function when a cron process is killed from the command line (via Ctrl+c) or with the kill command? I have tried register_shutdown_function() , but it doesn't seem to be invoked when the script is killed, but does get invoked when the script ends normally. I am trying to log the result to a file and update a database value when a cron instance is killed automatically (ie. has been running too long). 回答1: According to a comment in the manual on register_shutdown

PHP's register_shutdown_function to fire when a script is killed from the command line?

孤街浪徒 提交于 2020-01-21 06:34:04
问题 Is it possible to invoke a function when a cron process is killed from the command line (via Ctrl+c) or with the kill command? I have tried register_shutdown_function() , but it doesn't seem to be invoked when the script is killed, but does get invoked when the script ends normally. I am trying to log the result to a file and update a database value when a cron instance is killed automatically (ie. has been running too long). 回答1: According to a comment in the manual on register_shutdown

Why won't this shutdownhook work?

北城以北 提交于 2020-01-03 15:56:03
问题 This is my main method and it contains a shutdownhook: public static void main(String args[]) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { JOptionPane.showMessageDialog(null, "Shutdown hook"); } }); /* Create and display the form */ java.awt.EventQueue.invokeLater( new Runnable() { @Override public void run() { Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); MyFrame frame = new MyFrame(); frame.setVisible(true); } }); } The

Why won't this shutdownhook work?

半世苍凉 提交于 2020-01-03 15:54:47
问题 This is my main method and it contains a shutdownhook: public static void main(String args[]) { Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { JOptionPane.showMessageDialog(null, "Shutdown hook"); } }); /* Create and display the form */ java.awt.EventQueue.invokeLater( new Runnable() { @Override public void run() { Thread.setDefaultUncaughtExceptionHandler(new MyUncaughtExceptionHandler()); MyFrame frame = new MyFrame(); frame.setVisible(true); } }); } The

shutdown hook vs finalizer method

偶尔善良 提交于 2019-12-29 06:43:20
问题 I just fail to understand why must one use Runtime.addShutdownHook. If you want to do some cleanup when the jvm exits, why not just overload the finalize method of the daemon class. What is the advantage of using shutdown hook over finalize method. Also there is a deprecated function runFinalizersOnExit. If I set it to false, I believe finalizers won't run. This contradicts the java guarantee that finalizers always run before garbage collections. 回答1: There is no guarantee that a finalizer

Run a script only at shutdown (not log off or restart) on Mac OS X

≯℡__Kan透↙ 提交于 2019-12-28 04:08:09
问题 Is there any way to run a script only at shutdown? I mean, only when the computer is really shutting down to off state. This script should not run when doing just a log off or restart. 回答1: Few days ago I published on github a configuration/script able to be executed at boot/shutdown. Basically on Mac OS X you could/should use a System wide and per-user daemon/agent configuration file (plist) in conjunction with a bash script file. This is a sample of the plist file you could use: <?xml

How to make a Java program that cannot be killed from command line? [duplicate]

こ雲淡風輕ζ 提交于 2019-12-25 04:46:07
问题 This question already has answers here : How can I “intercept” Ctrl+C in a CLI application? (4 answers) Closed 4 years ago . I am trying to run a Java program that appears to have "9 lives". It simply prints out, in an infinite loop, the following when we run it: GlobalVar = 1 GlobalVar = 1 GlobalVar = 1 /* etc */ GlobalVar = 1 GlobalVar = 1 Then once we CTRL+C and kill the program, rather than quitting and going to the command prompt ... it should continue anew like this: GlobalVar = 2

How to get return code in shutdown hook

半腔热情 提交于 2019-12-23 08:54:29
问题 I need to modify JVM return code according to my application result. But it is risky to explicitly call System.exit(code) coz the application is complicated and it is hard to identify the end of running threads. So I come up with using shutdown hook to modify the return code before JVM exit. But there is a problem that how can I get the original return code of JVM coz it may be an error code not 0. 回答1: You should not call exit method in shutdown hook, System.exit(status) internally calls

How to implement thread pool that will automatically shutdown at end of execution?

*爱你&永不变心* 提交于 2019-12-22 13:01:02
问题 I'm writing a Java client which could theoretically be used in a different environment: Java main(), in a servlet container, or via dependency injection. The client implements internal connection thread pooling. The problem with this approach is that users of the client that are unaware of the fact that an internal thread pool is implemented will see his or her application "hang" on shutdown. My users need to know to send a shutdown() message to the library. I'm wondering if any other