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

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

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

Runtime.halt介绍

[英]Causes the VM to stop running, and the program to exit with the given return code. Use 0 to signal success to the calling process and 1 to signal failure. Neither shutdown hooks nor finalizers are run before exiting. This method is unlikely to be useful to an Android application.
[中]导致VM停止运行,程序以给定的返回代码退出。使用0表示呼叫进程成功,使用1表示失败。退出之前,关闭挂钩和终结器都不会运行。这种方法不太可能对Android应用程序有用。

代码示例

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

  1. public void run () {
  2. Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
  3. }
  4. };

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

  1. public void run () {
  2. Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
  3. }
  4. };

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

  1. public void run () {
  2. Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
  3. }
  4. };

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

  1. public void run () {
  2. Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
  3. }
  4. };

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

  1. @Override
  2. public void execute(int statusCode, String message) {
  3. Runtime.getRuntime().halt(statusCode);
  4. }
  5. };

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

  1. public static void haltProcess(int val) {
  2. Runtime.getRuntime().halt(val);
  3. }

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

  1. public static void haltProcess(int val) {
  2. Runtime.getRuntime().halt(val);
  3. }

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

  1. private void handleServerException(Exception ex) {
  2. LOG.error("ThriftServer is being stopped due to: " + ex, ex);
  3. if (server != null) {
  4. server.stop();
  5. }
  6. Runtime.getRuntime().halt(1); //shutdown server process since we could not handle Thrift requests any more
  7. }

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

  1. public static void handleUncaughtException(Throwable t) {
  2. if (t != null && t instanceof Error) {
  3. if (t instanceof OutOfMemoryError) {
  4. try {
  5. System.err.println("Halting due to Out Of Memory Error..." + Thread.currentThread().getName());
  6. } catch (Throwable err) {
  7. // Again we don't want to exit because of logging issues.
  8. }
  9. Runtime.getRuntime().halt(-1);
  10. } else {
  11. // Running in daemon mode, we would pass Error to calling thread.
  12. throw (Error) t;
  13. }
  14. }
  15. }

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

  1. public static void halt_process(int val, String msg) {
  2. LOG.info("Halting process: " + msg);
  3. try {
  4. Thread.sleep(1000);
  5. } catch (InterruptedException e) {
  6. LOG.error("halt_process", e);
  7. }
  8. Runtime.getRuntime().halt(val);
  9. }

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

  1. public static void handleUncaughtException(Throwable t, Set<Class> allowedExceptions) {
  2. if (t != null) {
  3. if (t instanceof OutOfMemoryError) {
  4. try {
  5. System.err.println("Halting due to Out Of Memory Error..." + Thread.currentThread().getName());
  6. } catch (Throwable err) {
  7. //Again we don't want to exit because of logging issues.
  8. }
  9. Runtime.getRuntime().halt(-1);
  10. }
  11. }
  12. if (allowedExceptions.contains(t.getClass())) {
  13. LOG.info("Swallowing {} {}", t.getClass(), t);
  14. return;
  15. }
  16. //Running in daemon mode, we would pass Error to calling thread.
  17. throw new Error(t);
  18. }

代码示例来源:origin: org.apache.hadoop/hadoop-common

  1. /**
  2. * Handler for out of memory events -no attempt is made here
  3. * to cleanly shutdown or support halt blocking; a robust
  4. * printing of the event to stderr is all that can be done.
  5. * @param oome out of memory event
  6. */
  7. public static void haltOnOutOfMemory(OutOfMemoryError oome) {
  8. //After catching an OOM java says it is undefined behavior, so don't
  9. //even try to clean up or we can get stuck on shutdown.
  10. try {
  11. System.err.println("Halting due to Out Of Memory Error...");
  12. } catch (Throwable err) {
  13. //Again we done want to exit because of logging issues.
  14. }
  15. Runtime.getRuntime().halt(-1);
  16. }
  17. }

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

  1. @Override public void run() {
  2. try {
  3. if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
  4. U.error(log, "Stopping local node timeout, JVM will be halted.");
  5. Runtime.getRuntime().halt(Ignition.KILL_EXIT_CODE);
  6. }
  7. }
  8. catch (InterruptedException e) {
  9. // No-op.
  10. }
  11. }
  12. },

代码示例来源:origin: spotify/helios

  1. @Override
  2. public void handle(Signal signal) {
  3. if (exitSignalTriggered.get()) {
  4. System.err.println("Exiting with extreme prejudice due to " + signal);
  5. // Really exit
  6. Runtime.getRuntime().halt(0);
  7. } else {
  8. System.err.println("Attempting gentle exit on " + signal);
  9. exitSignalTriggered.set(true);
  10. existingExitHandler.get().handle(signal);
  11. }
  12. }
  13. };

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

  1. public static boolean exitIfOOME(final Throwable e ){
  2. boolean stop = false;
  3. try {
  4. if (e instanceof OutOfMemoryError
  5. || (e.getCause() != null && e.getCause() instanceof OutOfMemoryError)
  6. || (e.getMessage() != null && e.getMessage().contains(
  7. "java.lang.OutOfMemoryError"))) {
  8. stop = true;
  9. LOG.error(HBaseMarkers.FATAL, "Run out of memory; "
  10. + RSRpcServices.class.getSimpleName() + " will abort itself immediately",
  11. e);
  12. }
  13. } finally {
  14. if (stop) {
  15. Runtime.getRuntime().halt(1);
  16. }
  17. }
  18. return stop;
  19. }

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

  1. /**
  2. * Adds the user supplied function as a shutdown hook for cleanup. Also adds a function that sleeps for numSecs and then halts the
  3. * runtime to avoid any zombie process in case cleanup function hangs.
  4. */
  5. public static void addShutdownHookWithDelayedForceKill(Runnable func, int numSecs) {
  6. final Thread sleepKill = new Thread(() -> {
  7. try {
  8. LOG.info("Halting after {} seconds", numSecs);
  9. Time.sleepSecs(numSecs);
  10. LOG.warn("Forcing Halt... {}", Utils.threadDump());
  11. Runtime.getRuntime().halt(20);
  12. } catch (InterruptedException ie) {
  13. //Ignored/expected...
  14. } catch (Exception e) {
  15. LOG.warn("Exception in the ShutDownHook", e);
  16. }
  17. });
  18. sleepKill.setDaemon(true);
  19. Thread wrappedFunc = new Thread(() -> {
  20. func.run();
  21. sleepKill.interrupt();
  22. });
  23. Runtime.getRuntime().addShutdownHook(wrappedFunc);
  24. Runtime.getRuntime().addShutdownHook(sleepKill);
  25. }

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

  1. @Override
  2. public void run() {
  3. if (state(name) == IgniteState.STARTED) {
  4. U.error(null, "Unable to gracefully stop node within timeout " + timeoutMs +
  5. " milliseconds. Killing node...");
  6. // We are not able to kill only one grid so whole JVM will be stopped.
  7. Runtime.getRuntime().halt(Ignition.KILL_EXIT_CODE);
  8. }
  9. }
  10. }, timeoutMs, TimeUnit.MILLISECONDS);

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

  1. @Override
  2. public void flatMap(Long key, Collector<String> collector) throws IOException {
  3. if (allocationFailureMessage != null) {
  4. // Report the failure downstream, so that we can get the message from the output.
  5. collector.collect(allocationFailureMessage);
  6. allocationFailureMessage = null;
  7. }
  8. if (failTask) {
  9. // we fail the task, either by killing the JVM hard, or by throwing a user code exception.
  10. if (killTaskOnFailure) {
  11. Runtime.getRuntime().halt(-1);
  12. } else {
  13. throw new RuntimeException("Artificial user code exception.");
  14. }
  15. }
  16. // sanity check
  17. if (null != valueState.value()) {
  18. throw new IllegalStateException("This should never happen, keys are generated monotonously.");
  19. }
  20. // store artificial data to blow up the state
  21. valueState.update(RandomStringUtils.random(valueSize, true, true));
  22. }

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

  1. public void serve() {
  2. try {
  3. // locate our thrift transport plugin
  4. ITransportPlugin transportPlugin = AuthUtils.GetTransportPlugin(_type, _storm_conf, _login_conf);
  5. // server
  6. _server = transportPlugin.getServer(_processor);
  7. // start accepting requests
  8. _server.serve();
  9. } catch (Exception ex) {
  10. LOG.error("ThriftServer is being stopped due to: " + ex, ex);
  11. if (_server != null)
  12. _server.stop();
  13. Runtime.getRuntime().halt(1); // shutdown server process since we could not handle Thrift requests any more
  14. }
  15. }
  16. }

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

  1. /** {@inheritDoc} */
  2. @Override public void clear() throws IOException {
  3. super.clear();
  4. System.err.println("Truncated file: " + file.getAbsolutePath());
  5. truncations.incrementAndGet();
  6. Integer checkpointedPart = null;
  7. try {
  8. Field field = GridDhtLocalPartition.class.getDeclaredField("partWhereTestCheckpointEnforced");
  9. field.setAccessible(true);
  10. checkpointedPart = (Integer) field.get(null);
  11. }
  12. catch (Exception e) {
  13. e.printStackTrace();
  14. }
  15. // Wait while more than one file have truncated and checkpoint on partition eviction has done.
  16. if (truncations.get() > 1 && checkpointedPart != null) {
  17. System.err.println("JVM is going to be crushed for test reasons...");
  18. Runtime.getRuntime().halt(0);
  19. }
  20. }
  21. }

相关文章