Java application does not receive SIGNALS on Ubuntu 12.04

Strange problem

I am trying to close the Java application properly when receiving a signal, or send manually via kill. I tried to kill SIGTERM, SIGHUP, SIGINT, etc., And every time the JVM just stops without calling Runtime shutdown hooks, it finally blocks or signals traps created in Java code.

Runtime.getRuntime().addShutdownHook(new Thread("Shutdown hook") { @Override public void run() { vd.pretendRemoveAll(); } }); 

And added handlers when shutdownHook is not working

  SignalHandler h = new SignalHandler() { @Override public synchronized void handle(Signal sig) { _logger.warn("Received signal: {}", sig); vd.pretendRemoveAll(); System.exit(0); } }; Signal.handle(new Signal("INT"), h); Signal.handle(new Signal("KILL"), h); Signal.handle(new Signal("HUP"), h); Signal.handle(new Signal("TERM"), h); 

I am working on Ubuntu 12.04 with Java java version "1.6.0_24"

OpenJDK workspace (IcedTea6 1.11.5) (6b24-1.11.5-0ubuntu1 ~ 12.04.1)

OpenJDK 64-bit virtual machine (build 20.0-b12, mixed mode)

I also tried using Oracle Java jdk1.6.0_37, same effect

When I use strace in the process to find out what happens, I get:

user @server: ~ / appdir $ sudo strace -v -p 32277 Process 32277 attached - interrupt to quitfutex (0x7f667f07d9d0, FUTEX_WAIT, 32278, NULL) =? ERESTARTSYS (for restarting) --- SIGTERM (Terminated) @ 0 (0) --- futex (0x7f667e2543e0, FUTEX_WAKE_PRIVATE, 1) = 1 rt_sigreturn (0x7f667e2543e0) = 202 futex (0x7f667f07d278_832877827827877877827877827877877877877877877877877877877877277877877877277877d2d2d2d2d2d2d2d2d2d2d2d7d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8id8d8d8d8d8d8id8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8d8dit2did2d8278_tp from 143

And this NULLPANIC looks suspicious, but I have no idea what's next.

I tested this code on Mac and did not work. Any ideas that are causing the problem and how to fix it? Should a specific security function / security policy be installed?

+4
source share
1 answer

This code, below from http://hellotojavaworld.blogspot.fr/2010/11/runtimeaddshutdownhook.html , works well on Ubuntu, jdk 1.6.30, what do you call the addShutdownHook method? you should be in the class, not in the static main method.

 public class AddShutdownHookSample { public void attachShutDownHook(){ Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { System.out.println("Inside Add Shutdown Hook"); } }); System.out.println("Shut Down Hook Attached."); } public static void main(String[] args) throws InterruptedException { AddShutdownHookSample sample = new AddShutdownHookSample(); sample.attachShutDownHook(); Thread.sleep(1000*60*1); //Print a message System.out.println("Last instruction of Program...."); System.exit(0); }} 
-1
source

All Articles