Java error: java.lang.IllegalArgumentException: Signal already used by VM: INT

I am investigating a Java issue (using IBM JVM 1.4.2 64-bit) on Red Hat Linux. I am wondering if anyone has seen this error message before and knows if there is a workaround to this problem? Source: import sun.misc.Signal; import sun.misc.SignalHandler; public class SignalTest extends Thread { private static Signal signal = new Signal("INT"); private static ShutdownHandler handler = new ShutdownHandler(); private static class ShutdownHandler implements SignalHandler { public void handle(Signal sig) { } } public static void main(String[] args) { try { Signal.handle(signal, handler); } catch(Throwable e) { e.printStackTrace(); } try { Thread.sleep(5000); } catch(Exception e) { e.printStackTrace(); } System.exit(0); } } Output: java.lang.IllegalArgumentException java.lang.IllegalArgumentException: Signal already used by VM: INT at at sun.misc.Signal.handle( at xxx Additional Information: I found out something strange. The reason why it fails is because I am running the program inside a shell script as a background process. i.e. #!/bin/bash java -cp . SignalTest >> sigtest.log 2>&1 & If I run the program from the command line, or remove the "&" (i.e. make it a foreground process inside the shell script), it doesn't have a problem... I don't understand why this is the case.
Jin, given your comment on my answer, the JVM isn't letting you register a hook on this event. Can you describe more about what you are trying to accomplish? Maybe there is a way to do it that is more in sync with the JVM's expectation.

以上就是Java error: java.lang.IllegalArgumentException: Signal already used by VM: INT的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准