Dynamic, reflective SignalHandler in Java
- by pilcrow
How do I install signal handling logic iff sun.misc.Signal is available?
Background
First generation of my code looked something like this:
class MyApp {
public static void main(String[] args) {
...
Signal.handle(term_sig, new SignalHandler() {
public void handle(Signal sig) { ... }
});
...
}
}
I believe I understand how to reflectively test for and use signal handlers -- Class.forName("sun.misc.Signal"), reflectively call Signal.handle, and so forth.
My impulse was simply to instantiate another anonymous inner class with the dynamically obtained SignalHandler class, but I think that's just wishful syntax.