3

I want to catch SIGUSR1 or SIGUSR2 in my spring boot application and trigger a logic. Is there a way to do that?

Spring boot version - 2.6 , java version 11, Tomcat version 9.0.65

AP_22
  • 53
  • 5
  • Maybe trap it in a script that starts it. See `man bash` https://wiki.bash-hackers.org/commands/builtin/trap – g00se Apr 18 '22 at 16:58
  • Does this answer your question? [How to gracefully handle the SIGKILL signal in Java](https://stackoverflow.com/questions/2541597/how-to-gracefully-handle-the-sigkill-signal-in-java) – Robert Apr 18 '22 at 17:11
  • Catching signals in Java is not in any stable API. The signal handling would have to be JDK specific. – Carl Mastrangelo Apr 18 '22 at 18:46
  • @Robert, that is specifically for SIGKILL. I need something for catching any signal that is not a kill/terminate/interrupt signal. Like SIGUSR1, SIGUSR2 – AP_22 Apr 19 '22 at 05:17
  • @CarlMastrangelo is there something I can use for jdk 11? I tried sun.misc.Signal class, but that seems to be deprecated. – AP_22 Apr 19 '22 at 05:19
  • 1
    It's a bit of a faff but you can write a JVMTI handler to get notified when SIGQUIT is sent to your application. I've been using this in our agent to start/stop java recording. See https://docs.oracle.com/javase/8/docs/platform/jvmti/jvmti.html#DataDumpRequest – Dave Griffiths May 22 '23 at 17:38

0 Answers0