-
Notifications
You must be signed in to change notification settings - Fork 2
/
TestSignal.java
47 lines (45 loc) · 1.31 KB
/
TestSignal.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
class TestSignal implements sun.misc.SignalHandler {
private static boolean running;
public static void main(final String[] args) throws InterruptedException
{
running = true;
TestSignal handler = new TestSignal();
//handler.handleSignal("HUB");
handler.handleSignal("INT");
handler.handleSignal("TERM");
while (running)
{
Thread.sleep(1000);
System.out.println("sleeping ...");
}
System.out.println("finished");
}
public void handleSignal( final String signalName ) throws IllegalArgumentException
{
try
{
sun.misc.Signal.handle( new sun.misc.Signal(signalName), this );
}
catch( IllegalArgumentException x )
{
// Most likely this is a signal that's not supported on this
// platform or with the JVM as it is currently configured
throw x;
}
catch( Throwable x )
{
// We may have a serious problem, including missing classes
// or changed APIs
throw new IllegalArgumentException( "Signal unsupported: "+signalName, x );
}
}
/**
* Called by Sun Microsystems' signal trapping routines in the JVM.
* @param signal The {@link sun.misc.Signal} that we received
**/
public void handle( final sun.misc.Signal signal )
{
System.out.println("signal catch");
running = false;
}
}