java.lang.Runtime.exit()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(360)

本文整理了Java中java.lang.Runtime.exit()方法的一些代码示例,展示了Runtime.exit()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Runtime.exit()方法的具体详情如下:
包路径:java.lang.Runtime
类名称:Runtime
方法名:exit

Runtime.exit介绍

[英]Causes the VM to stop running and the program to exit. If #runFinalizersOnExit(boolean) has been previously invoked with a true argument, then all objects will be properly garbage-collected and finalized first. Use 0 to signal success to the calling process and 1 to signal failure. This method is unlikely to be useful to an Android application.
[中]导致VM停止运行并退出程序。如果#runFinalizersOnExit(boolean)以前使用true参数调用过,那么所有对象都将被正确地垃圾收集并首先完成。使用0表示呼叫进程成功,使用1表示失败。这种方法不太可能对Android应用程序有用。

代码示例

代码示例来源:origin: google/guava

@Override
 public void uncaughtException(Thread t, Throwable e) {
  try {
   // cannot use FormattingLogger due to a dependency loop
   logger.log(
     SEVERE, String.format(Locale.ROOT, "Caught an exception in %s.  Shutting down.", t), e);
  } catch (Throwable errorInLogging) {
   // If logging fails, e.g. due to missing memory, at least try to log the
   // message and the cause for the failed logging.
   System.err.println(e.getMessage());
   System.err.println(errorInLogging.getMessage());
  } finally {
   runtime.exit(1);
  }
 }
}

代码示例来源:origin: apache/storm

public static void exitProcess(int val, String msg) {
  String combinedErrorMessage = "Halting process: " + msg;
  LOG.error(combinedErrorMessage, new RuntimeException(combinedErrorMessage));
  Runtime.getRuntime().exit(val);
}

代码示例来源:origin: robovm/robovm

/**
 * Causes the VM to stop running and the program to exit with the given exit status.
 * If {@link #runFinalizersOnExit(boolean)} has been previously invoked with a
 * {@code true} argument, then all objects will be properly
 * garbage-collected and finalized first.
 */
public static void exit(int code) {
  Runtime.getRuntime().exit(code);
}

代码示例来源:origin: prestodb/presto

@Override
 public void uncaughtException(Thread t, Throwable e) {
  try {
   // cannot use FormattingLogger due to a dependency loop
   logger.log(
     SEVERE, String.format(Locale.ROOT, "Caught an exception in %s.  Shutting down.", t), e);
  } catch (Throwable errorInLogging) {
   // If logging fails, e.g. due to missing memory, at least try to log the
   // message and the cause for the failed logging.
   System.err.println(e.getMessage());
   System.err.println(errorInLogging.getMessage());
  } finally {
   runtime.exit(1);
  }
 }
}

代码示例来源:origin: ballerina-platform/ballerina-lang

@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line, int charPositionInLine,
            String msg, RecognitionException e) {
  if (filePath == null) {
    return;
  }
  String errorMsg = "invalid toml syntax at " + filePath + ":" + line;
  errStream.println("error: " + errorMsg);
  Runtime.getRuntime().exit(1);
}

代码示例来源:origin: twitter/distributedlog

@Override
public void onFailure(Throwable cause) {
  System.out.println("Encountered error on writing data");
  cause.printStackTrace(System.err);
  Runtime.getRuntime().exit(0);
}

代码示例来源:origin: twitter/distributedlog

@Override
public void onFailure(Throwable cause) {
  System.out.println("Encountered error on writing data");
  cause.printStackTrace(System.err);
  Runtime.getRuntime().exit(0);
}

代码示例来源:origin: twitter/distributedlog

@Override
public void onFailure(Throwable cause) {
  System.out.println("Encountered error on writing data");
  cause.printStackTrace(System.err);
  Runtime.getRuntime().exit(0);
}

代码示例来源:origin: twitter/distributedlog

@Override
public void onFailure(Throwable cause) {
  System.out.println("Encountered error on writing data");
  cause.printStackTrace(System.err);
  Runtime.getRuntime().exit(0);
}

代码示例来源:origin: twitter/distributedlog

@Override
public void onFailure(Throwable cause) {
  System.out.println("Encountered error on writing data");
  cause.printStackTrace(System.err);
  Runtime.getRuntime().exit(0);
}

代码示例来源:origin: twitter/distributedlog

@Override
public void onFailure(Throwable cause) {
  System.out.println("Encountered error on writing data");
  cause.printStackTrace(System.err);
  Runtime.getRuntime().exit(0);
}

代码示例来源:origin: apache/storm

public void uncaughtException(Thread thread, Throwable thrown) {
    try {
      handleUncaughtException(thrown);
    } catch (Error err) {
      LOG.error("Received error in main thread.. terminating server...", err);
      Runtime.getRuntime().exit(-2);
    }
  }
});

代码示例来源:origin: google/j2objc

@Override
 public void uncaughtException(Thread t, Throwable e) {
  try {
   // cannot use FormattingLogger due to a dependency loop
   logger.log(
     SEVERE, String.format(Locale.ROOT, "Caught an exception in %s.  Shutting down.", t), e);
  } catch (Throwable errorInLogging) {
   // If logging fails, e.g. due to missing memory, at least try to log the
   // message and the cause for the failed logging.
   System.err.println(e.getMessage());
   System.err.println(errorInLogging.getMessage());
  } finally {
   runtime.exit(1);
  }
 }
}

代码示例来源:origin: apache/hbase

protected static void printUsageAndExit() {
 StringBuilder sb = new StringBuilder();
 sb.append("Usage: OfflineMetaRepair [opts]\n").
   append(" where [opts] are:\n").
   append("   -details               Display full report of all regions.\n").
   append("   -base <hdfs://>        Base Hbase Data directory.\n").
   append("   -sidelineDir <hdfs://> HDFS path to backup existing meta and root.\n").
   append("   -fix                   Auto fix as many problems as possible.\n").
   append("   -fixHoles              Auto fix as region holes.");
 System.err.println(sb.toString());
 Runtime.getRuntime().exit(-2);
}

代码示例来源:origin: alibaba/jstorm

@Override
  public void uncaughtException(Thread a, Throwable e) {
    try {
      Utils.handleUncaughtException(e);
    } catch (Error error) {
      LOG.info("Received error in main thread.. terminating server...", error);
      Runtime.getRuntime().exit(-2);
    }
  }
}

代码示例来源:origin: apache/storm

@Override
  public void uncaughtException(Thread t, Throwable e) {
    try {
      LOG.error("Uncaught exception in netty " + e.getCause());
    } catch (Throwable err) {
      // Doing nothing (probably due to an oom issue) and hoping Utils.handleUncaughtException will handle it
    }

    try {
      Utils.handleUncaughtException(e);
    } catch (Throwable throwable) {
      LOG.error("Exception thrown while handling uncaught exception " + throwable.getCause());
    }
    LOG.info("Received error in netty thread.. terminating server...");
    Runtime.getRuntime().exit(1);
  }
}

代码示例来源:origin: twitter/distributedlog

@Override
public void onFailure(Throwable cause) {
  recordSetWriter.abortTransmit(cause);
  System.out.println("Encountered error on writing data");
  cause.printStackTrace(System.err);
  Runtime.getRuntime().exit(0);
}

代码示例来源:origin: apache/storm

@Override
  public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
    try {
      LOG.error("server errors in handling the request", cause);
    } catch (Throwable err) {
      // Doing nothing (probably due to an oom issue) and hoping Utils.handleUncaughtException will handle it
    }
    try {
      Utils.handleUncaughtException(cause, ALLOWED_EXCEPTIONS);
      ctx.close();
    } catch (Error error) {
      LOG.info("Received error in netty thread.. terminating server...");
      Runtime.getRuntime().exit(1);
    }

  }
}

代码示例来源:origin: apache/storm

private void sleepUntilSufficientTimeElapsed() {
  long now = System.currentTimeMillis();
  if (now - getLastLogin() < MIN_TIME_BEFORE_RELOGIN) {
    LOG.warn("Not attempting to re-login since the last re-login was " +
         "attempted less than " + (MIN_TIME_BEFORE_RELOGIN / 1000) + " seconds" +
         " before.");
    try {
      Thread.sleep(MIN_TIME_BEFORE_RELOGIN - (now - getLastLogin()));
    } catch (InterruptedException e) {
      LOG.warn("TGT renewal thread has been interrupted and will exit.");
      Runtime.getRuntime().exit(-2);
    }
  }
  // register most recent relogin attempt
  setLastLogin(System.currentTimeMillis());
}

代码示例来源:origin: google/guava

public void testExiter() {
  new Exiter(runtimeMock).uncaughtException(new Thread(), new Exception());
  verify(runtimeMock).exit(1);
 }
}

相关文章