本文整理汇总了Java中sun.misc.SignalHandler类的典型用法代码示例。如果您正苦于以下问题:Java SignalHandler类的具体用法?Java SignalHandler怎么用?Java SignalHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SignalHandler类属于sun.misc包,在下文中一共展示了SignalHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enterMainThread
import sun.misc.SignalHandler; //导入依赖的package包/类
public static void enterMainThread()
{
if(Thread.get_CurrentThread().get_Name() == null)
{
try
{
if(false) throw new InvalidOperationException();
Thread.get_CurrentThread().set_Name("main");
}
catch(InvalidOperationException _)
{
}
}
java.lang.Thread.currentThread();
try{
sun.misc.Signal.handle(new sun.misc.Signal("BREAK"), SignalHandler.SIG_DFL);
}catch(IllegalArgumentException ex){
// ignore it;
}
}
示例2: testRaiseNoConsumer
import sun.misc.SignalHandler; //导入依赖的package包/类
@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);
}
}
}
示例3: checkLastHandler
import sun.misc.SignalHandler; //导入依赖的package包/类
@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);
}
}
}
示例4: handle
import sun.misc.SignalHandler; //导入依赖的package包/类
/**
* Handle the caught signal dumping all locks and threads.
*/
public void handle(sun.misc.Signal sig) {
try {
final GemFireStore memStore = GemFireStore.getBootingInstance();
final Signal signal = Signal.valueOfName(sig.getName());
if (Signal.SIGURG.equals(signal)) {
final String header = "SIGURG received, full state dump";
GemFireXDUtils.dumpStacks(memStore, header);
}
else {
// just log any other unexpected signals
SanityManager.DEBUG_PRINT("warning:SignalHandler",
"received explicit OS signal SIG" + sig.getName(), new Throwable());
}
// Chain back to previous handler, if one exists
SignalHandler oldHandler = this.oldHandlers.get(signal);
if (oldHandler != null && oldHandler != SIG_DFL
&& oldHandler != SIG_IGN) {
oldHandler.handle(sig);
}
} catch (Throwable t) {
System.err.println("SigThreadDumpHandler failed to dump to log for SIG"
+ sig.getName() + ": " + SanityManager.getStackTrace(t));
}
}
示例5: setup
import sun.misc.SignalHandler; //导入依赖的package包/类
static void setup() {
if (handler != null) return;
SignalHandler sh = new SignalHandler() {
public void handle(Signal sig) {
Shutdown.exit(sig.getNumber() + 0200);
}
};
handler = sh;
try {
Signal.handle(new Signal("INT"), sh);
Signal.handle(new Signal("TERM"), sh);
} catch (IllegalArgumentException e) {
// When -Xrs is specified the user is responsible for
// ensuring that shutdown hooks are run by calling
// System.exit()
}
}
示例6: renderOutput
import sun.misc.SignalHandler; //导入依赖的package包/类
public void renderOutput(PrintStream out, OutputFormat outputFormat, boolean interactive)
{
Thread clientThread = Thread.currentThread();
SignalHandler oldHandler = Signal.handle(SIGINT, signal -> {
if (ignoreUserInterrupt.get() || client.isClosed()) {
return;
}
userAbortedQuery.set(true);
client.close();
clientThread.interrupt();
});
try {
renderQueryOutput(out, outputFormat, interactive);
}
finally {
Signal.handle(SIGINT, oldHandler);
Thread.interrupted(); // clear interrupt status
}
}
示例7: startSignalHandler
import sun.misc.SignalHandler; //导入依赖的package包/类
/**
* <p>
* startSignalHandler
* </p>
*/
protected void startSignalHandler() {
Signal.handle(new Signal("INT"), new SignalHandler() {
private boolean interrupted = false;
@Override
public void handle(Signal arg0) {
if (interrupted)
System.exit(0);
try {
interrupted = true;
if (process != null)
process.waitFor();
} catch (InterruptedException e) {
logger.warn("",e);
}
}
});
}
示例8: setup
import sun.misc.SignalHandler; //导入依赖的package包/类
static void setup() {
if (handler != null) return;
SignalHandler sh = new SignalHandler() {
public void handle(Signal sig) {
Shutdown.exit(sig.getNumber() + 0200);
}
};
handler = sh;
try {
Signal.handle(new Signal("INT"), sh);
Signal.handle(new Signal("TERM"), sh);
} catch (IllegalArgumentException e) {
// When -Xrs is specified the user is responsible for
// ensuring that shutdown hooks are run by calling
// System.exit()
}
}
示例9: setup
import sun.misc.SignalHandler; //导入依赖的package包/类
static void setup() {
if (handler != null) return;
SignalHandler sh = new SignalHandler() {
public void handle(Signal sig) {
Shutdown.exit(sig.getNumber() + 0200);
}
};
handler = sh;
try {
Signal.handle(new Signal("HUP"), sh);
Signal.handle(new Signal("INT"), sh);
Signal.handle(new Signal("TERM"), sh);
} catch (IllegalArgumentException e) {
// When -Xrs is specified the user is responsible for
// ensuring that shutdown hooks are run by calling
// System.exit()
}
}
示例10: handleShutdown
import sun.misc.SignalHandler; //导入依赖的package包/类
public static boolean handleShutdown(Class<?> clazz, String[] args,
final AtomicBoolean running) {
if (args != null && args.length > 0 && args[0].equals("stop")) {
running.set(false);
return true;
}
SignalHandler handler = new SignalHandler() {
@Override
public void handle(Signal signal) {
running.set(false);
}
};
String command = System.getProperty("sun.java.command");
if (command == null || command.isEmpty()) {
return false;
}
if (clazz.getName().equals(command.split(" ")[0])) {
Signal.handle(new Signal("INT"), handler);
Signal.handle(new Signal("TERM"), handler);
}
return false;
}
示例11: addUnixSignalStatusHandle
import sun.misc.SignalHandler; //导入依赖的package包/类
private static void addUnixSignalStatusHandle() {
Signal.handle(new Signal("USR2"), new SignalHandler() {
@Override
public void handle(Signal sig) {
System.err.print("::: "+new Date()+" ::: RECIVE SIGNAL "+sig+" ::: Internal Server Status: ");
if(sig!=null){
if(status==STATUS_STARTING){
System.err.println("'STATUS_STARTING' :::");
}else if(status==STATUS_RUNNING){
System.err.println("'STATUS_RUNNING' :::");
}else if(status==STATUS_STOPING){
System.err.println("'STATUS_STOPING' :::");
}else{
System.err.println("'STATUS_UNKNOWN' :::");
}
}
System.err.flush();
}
});
}
示例12: configureSignalHandler
import sun.misc.SignalHandler; //导入依赖的package包/类
private void configureSignalHandler() {
SignalHandler handler = new SignalHandler() {
public void handle(Signal sig) {
logger.info("Got " + sig.getName() + " signal, canceling cell execution");
cancelExecution();
}
};
if (!isWindows()) {
Signal.handle(new Signal("INT"), handler);
}
}
示例13: handleDefault
import sun.misc.SignalHandler; //导入依赖的package包/类
protected void handleDefault(final sun.misc.Signal sig) {
final Signal signal = Signal.valueOfName(sig.getName());
switch (signal) {
case SIGINT:
break; // ignore the interrupt signal
default:
final SignalHandler handler = getOriginalSignalHandler(signal);
if (handler != null) {
handler.handle(sig);
}
}
}
示例14: isDaemonThread
import sun.misc.SignalHandler; //导入依赖的package包/类
/**
* 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; ");
}
示例15: SigThreadDumpHandler
import sun.misc.SignalHandler; //导入依赖的package包/类
private SigThreadDumpHandler() {
this.oldHandlers = Collections
.synchronizedMap(new HashMap<Signal, SignalHandler>());
// set of signals to be ignored because they are not fatal or informational
List<String> ignoredSignals = new ArrayList<String>() {{
add("WINCH");
add("CHLD");
add("CONT");
add("CLD");
add("BUS"); // Specifically for Mac OS X
add("USR1");
add("USR2");
}};
mergeIgnoredSignalsFromProps(ignoredSignals);
if (!ignoredSignals.contains("*")) {
for (final Signal signal : Signal.values) {
if (ignoredSignals.contains(signal.getName())) {
continue;
}
try {
sun.misc.Signal osSignal = new sun.misc.Signal(signal.getName());
this.oldHandlers.put(signal, sun.misc.Signal.handle(osSignal, this));
} catch (IllegalArgumentException iae) {
// move on to next one
}
}
}
}