shutdown-hook

Is it safe to send SIGTERM to JVM

六月ゝ 毕业季﹏ 提交于 2019-11-30 16:57:37
问题 Although JVM will translate SIGTERM and similar signals to shutdown hooks, many service shutdown scripts use a TCP port to initiate a shutdown. (e.g. Tomcat's shutdown port, Java Service Wrapper, JBoss' management interfaces, etc.) So I thought using signals and shutdown hooks to gracefully shutdown java services is discouraged, until I found that Play! framework is managing the service lifecycle with shutdown hooks and the startup scripts generated by play dist assumes that a signal will be

Detect windows logout event in Java application

杀马特。学长 韩版系。学妹 提交于 2019-11-29 12:08:17
Is there a library that I can use with Java to listen for user logout and possibly other Windows events? (Even better if it supports multiple platforms!) I remember reading about a library of this sort a number of years ago, but can't seem to find it now. I've seen other threads to do essentially the same thing using Python with win32ts. Also better if it's free and/or open source. Thanks. Note : The candidate solution of using Runtime.getRuntime().addShutdownHook(Thread) does not work correctly with javaw . I am still looking for a solution that will work with javaw. See java bug ids 4486580

debug_backtrace() from registered shutdown function in PHP

こ雲淡風輕ζ 提交于 2019-11-29 01:11:42
While tinkering for an answer to this question , I found that debug_backtrace() doesn't trace beyond the function registered to register_shutdown_function() , when called from within it. This was mentioned in this comment for register_shutdown_function() in the PHP docs, stating: You may get the idea to call debug_backtrace or debug_print_backtrace from inside a shutdown function, to trace where a fatal error occurred. Unfortunately, these functions will not work inside a shutdown function. Explained with a bit more detail, comments on this answer state: Doesn't work. The shutdown function

Shutdown hook doesn't work in Eclipse [duplicate]

纵然是瞬间 提交于 2019-11-28 08:58:05
This question already has an answer here: How to get shutdown hook to execute on a process launched from Eclipse 7 answers I have added a shutdown hook via: Runtime.getRuntime().addShutdownHook(myShutdownHook); It works fine normally, but not when I click the red stop button in Eclipse. Is there a way to make the shutdown hook be called in Eclipse? The red stop button forcibly kills the application, i.e. not gracefully, so the JVM doesn't know that the application is exiting, therefore the shutdown hooks are not invoked. Unfortunately, there is no way (in Windows, at least) to provide a

Detect windows logout event in Java application

大憨熊 提交于 2019-11-28 05:41:15
问题 Is there a library that I can use with Java to listen for user logout and possibly other Windows events? (Even better if it supports multiple platforms!) I remember reading about a library of this sort a number of years ago, but can't seem to find it now. I've seen other threads to do essentially the same thing using Python with win32ts. Also better if it's free and/or open source. Thanks. Note : The candidate solution of using Runtime.getRuntime().addShutdownHook(Thread) does not work

debug_backtrace() from registered shutdown function in PHP

痞子三分冷 提交于 2019-11-27 14:29:58
问题 While tinkering for an answer to this question, I found that debug_backtrace() doesn't trace beyond the function registered to register_shutdown_function() , when called from within it. This was mentioned in this comment for register_shutdown_function() in the PHP docs, stating: You may get the idea to call debug_backtrace or debug_print_backtrace from inside a shutdown function, to trace where a fatal error occurred. Unfortunately, these functions will not work inside a shutdown function.

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

强颜欢笑 提交于 2019-11-27 14:26:11
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. 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 version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs

Windows shutdown hook on java application run from a bat script

ε祈祈猫儿з 提交于 2019-11-27 13:14:47
I have a bat script which runs a java application. If I press ctrl+c on it, it the application terminates gracefully, invoking all the shutdown hooks. However, if I just close the cmd window of the bat script, the shutdown hooks are never invoked. Is there a way to solve this? Perhaps there's a way to tell the bat script how to terminate the invoked applications when its window is closed? From addShutdownHook documentation: In rare circumstances the virtual machine may abort, that is, stop running without shutting down cleanly. This occurs when the virtual machine is terminated externally, for

Shutdown hook doesn't work in Eclipse [duplicate]

强颜欢笑 提交于 2019-11-27 02:32:53
问题 This question already has an answer here: How to get shutdown hook to execute on a process launched from Eclipse 7 answers I have added a shutdown hook via: Runtime.getRuntime().addShutdownHook(myShutdownHook); It works fine normally, but not when I click the red stop button in Eclipse. Is there a way to make the shutdown hook be called in Eclipse? 回答1: The red stop button forcibly kills the application, i.e. not gracefully, so the JVM doesn't know that the application is exiting, therefore

Useful example of a shutdown hook in Java?

可紊 提交于 2019-11-26 03:19:11
问题 I\'m trying to make sure my Java application takes reasonable steps to be robust, and part of that involves shutting down gracefully. I am reading about shutdown hooks and I don\'t actually get how to make use of them in practice. Is there a practical example out there? Let\'s say I had a really simple application like this one below, which writes numbers to a file, 10 to a line, in batches of 100, and I want to make sure a given batch finishes if the program is interrupted. I get how to