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

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

本文整理了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

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

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

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

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

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

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

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

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

@Override
  public void execute(int statusCode, String message) {
    Runtime.getRuntime().halt(statusCode);
  }
};

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

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

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

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

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

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

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

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

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

public static void halt_process(int val, String msg) {
  LOG.info("Halting process: " + msg);
  try {
    Thread.sleep(1000);
  } catch (InterruptedException e) {
    LOG.error("halt_process", e);
  }
  Runtime.getRuntime().halt(val);
}

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

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

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

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

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

@Override public void run() {
    try {
      if (!latch.await(timeout, TimeUnit.MILLISECONDS)) {
        U.error(log, "Stopping local node timeout, JVM will be halted.");
        Runtime.getRuntime().halt(Ignition.KILL_EXIT_CODE);
      }
    }
    catch (InterruptedException e) {
      // No-op.
    }
  }
},

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

@Override
 public void handle(Signal signal) {
  if (exitSignalTriggered.get()) {
   System.err.println("Exiting with extreme prejudice due to " + signal);
   // Really exit
   Runtime.getRuntime().halt(0);
  } else {
   System.err.println("Attempting gentle exit on " + signal);
   exitSignalTriggered.set(true);
   existingExitHandler.get().handle(signal);
  }
 }
};

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

public static boolean exitIfOOME(final Throwable e ){
 boolean stop = false;
 try {
  if (e instanceof OutOfMemoryError
    || (e.getCause() != null && e.getCause() instanceof OutOfMemoryError)
    || (e.getMessage() != null && e.getMessage().contains(
      "java.lang.OutOfMemoryError"))) {
   stop = true;
   LOG.error(HBaseMarkers.FATAL, "Run out of memory; "
    + RSRpcServices.class.getSimpleName() + " will abort itself immediately",
    e);
  }
 } finally {
  if (stop) {
   Runtime.getRuntime().halt(1);
  }
 }
 return stop;
}

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

/**
 * Adds the user supplied function as a shutdown hook for cleanup. Also adds a function that sleeps for numSecs and then halts the
 * runtime to avoid any zombie process in case cleanup function hangs.
 */
public static void addShutdownHookWithDelayedForceKill(Runnable func, int numSecs) {
  final Thread sleepKill = new Thread(() -> {
    try {
      LOG.info("Halting after {} seconds", numSecs);
      Time.sleepSecs(numSecs);
      LOG.warn("Forcing Halt... {}", Utils.threadDump());
      Runtime.getRuntime().halt(20);
    } catch (InterruptedException ie) {
      //Ignored/expected...
    } catch (Exception e) {
      LOG.warn("Exception in the ShutDownHook", e);
    }
  });
  sleepKill.setDaemon(true);
  Thread wrappedFunc = new Thread(() -> {
    func.run();
    sleepKill.interrupt();
  });
  Runtime.getRuntime().addShutdownHook(wrappedFunc);
  Runtime.getRuntime().addShutdownHook(sleepKill);
}

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

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

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

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

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

public void serve() {
    try {
      // locate our thrift transport plugin
      ITransportPlugin transportPlugin = AuthUtils.GetTransportPlugin(_type, _storm_conf, _login_conf);

      // server
      _server = transportPlugin.getServer(_processor);

      // start accepting requests
      _server.serve();
    } catch (Exception ex) {
      LOG.error("ThriftServer is being stopped due to: " + ex, ex);
      if (_server != null)
        _server.stop();
      Runtime.getRuntime().halt(1); // shutdown server process since we could not handle Thrift requests any more
    }
  }
}

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

/** {@inheritDoc} */
  @Override public void clear() throws IOException {
    super.clear();
    System.err.println("Truncated file: " + file.getAbsolutePath());
    truncations.incrementAndGet();
    Integer checkpointedPart = null;
    try {
      Field field = GridDhtLocalPartition.class.getDeclaredField("partWhereTestCheckpointEnforced");
      field.setAccessible(true);
      checkpointedPart = (Integer) field.get(null);
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    // Wait while more than one file have truncated and checkpoint on partition eviction has done.
    if (truncations.get() > 1 && checkpointedPart != null) {
      System.err.println("JVM is going to be crushed for test reasons...");
      Runtime.getRuntime().halt(0);
    }
  }
}

相关文章