Dynamic, reflective SignalHandler in Java
Posted
by pilcrow
on Stack Overflow
See other posts from Stack Overflow
or by pilcrow
Published on 2010-05-06T18:48:05Z
Indexed on
2010/05/06
22:48 UTC
Read the original article
Hit count: 209
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.
© Stack Overflow or respective owner