Created
February 13, 2024 00:25
-
-
Save mbreese/90a166e4f1f86265a23e7733fc8705a8 to your computer and use it in GitHub Desktop.
Capture signals from Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.compgen.ngsutils.support; | |
import sun.misc.Signal; | |
import sun.misc.SignalHandler; | |
abstract public class CustomSignalHandler implements SignalHandler { | |
private SignalHandler old = null; | |
private void setOld(SignalHandler old) { | |
this.old = old; | |
} | |
public static void install(String sig, CustomSignalHandler handler) { | |
Signal SIG = new Signal(sig); | |
SignalHandler old = Signal.handle(SIG, handler); | |
handler.setOld(old); | |
} | |
@Override | |
public void handle(Signal sig) { | |
run(); | |
if (old != null) { | |
old.handle(sig); | |
} | |
} | |
abstract public void run(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment