本文整理汇总了Java中sun.misc.SignalHandler.SIG_IGN属性的典型用法代码示例。如果您正苦于以下问题:Java SignalHandler.SIG_IGN属性的具体用法?Java SignalHandler.SIG_IGN怎么用?Java SignalHandler.SIG_IGN使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类sun.misc.SignalHandler
的用法示例。
在下文中一共展示了SignalHandler.SIG_IGN属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRaiseNoConsumer
@Test
static void testRaiseNoConsumer() {
Signal signal = new Signal("INT");
SignalHandler orig = null;
try {
orig = Signal.handle(signal, SignalHandler.SIG_DFL);
printf("oldHandler: %s%n", orig);
if (orig == SignalHandler.SIG_IGN) {
// SIG_IGN for TERM means it cannot be handled
return;
}
Signal.raise(signal);
Assert.fail("Should have thrown IllegalArgumentException");
} catch (IllegalArgumentException iae) {
printf("IAE message: %s%n", iae.getMessage());
} finally {
// Restore original signal handler
if (orig != null && signal != null) {
Signal.handle(signal, orig);
}
}
}
示例2: checkLastHandler
@Test()
static void checkLastHandler() {
if (RUNNING_WITH_Xrs) {
return;
}
Signal signal = new Signal("TERM");
Handler h1 = new Handler();
Handler h2 = new Handler();
SignalHandler orig = Signal.handle(signal, h1);
if (orig == SignalHandler.SIG_IGN) {
// SIG_IGN for TERM means it cannot be handled
return;
}
try {
SignalHandler prev = Signal.handle(signal, h2);
Assert.assertSame(prev, h1, "prev handler mismatch");
prev = Signal.handle(signal, h1);
Assert.assertSame(prev, h2, "prev handler mismatch");
} finally {
if (orig != null && signal != null) {
Signal.handle(signal, orig);
}
}
}
示例3: isDaemonThread
/**
* The thread that runs the handler for sun.misc.Signal should be a
* Daemon thread.
*/
@Test
static void isDaemonThread() throws InterruptedException {
if (RUNNING_WITH_Xrs) {
return;
}
Handler handler = new Handler();
Signal signal = new Signal("INT");
SignalHandler orig = Signal.handle(signal, handler);
printf("oldHandler: %s%n", orig);
if (orig == SignalHandler.SIG_IGN) {
// SIG_IGN for INT means it cannot be handled
return;
}
Signal.raise(signal);
boolean handled = handler.semaphore()
.tryAcquire(Utils.adjustTimeout(100L), TimeUnit.MILLISECONDS);
if (!handled) {
// For debug try again
printf("Second try to see signal");
handled = handler.semaphore()
.tryAcquire(Utils.adjustTimeout(2L), TimeUnit.SECONDS);
}
Assert.assertEquals(handled, !RUNNING_WITH_Xrs,
"raising s.m.Signal did not get a callback;");
Assert.assertTrue(handler.wasDaemon(), "Thread.isDaemon running the handler; ");
}
示例4: getOriginalSignalHandler
protected SignalHandler getOriginalSignalHandler(final Signal signal) {
final SignalHandler handler = originalSignalHandlers.get(signal);
return (handler == SignalHandler.SIG_DFL || handler == SignalHandler.SIG_IGN ? null : handler);
}