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

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

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

Runtime.removeShutdownHook介绍

[英]Unregisters a previously registered VM shutdown hook.
[中]注销以前注册的VM关闭挂钩。

代码示例

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

  1. public void removeShutdownHook() {
  2. if (shutDownHook != null) {
  3. Runtime.getRuntime().removeShutdownHook(shutDownHook);
  4. }
  5. }

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

  1. private void removeShutdownHook(Shutdown shutdownHook) {
  2. try {
  3. Runtime.getRuntime().removeShutdownHook(shutdownHook);
  4. } catch (Exception e) {
  5. }
  6. }

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

  1. private void removeShutDownHook(Thread shutdownHook) {
  2. if (shutdownHook != null) {
  3. try {
  4. Runtime.getRuntime().removeShutdownHook(shutdownHook);
  5. } catch (Exception e) {
  6. }
  7. }
  8. }

代码示例来源:origin: apache/incubator-dubbo

  1. /**
  2. * Unregister the ShutdownHook
  3. */
  4. public void unregister() {
  5. if (registered.get() && registered.compareAndSet(true, false)) {
  6. Runtime.getRuntime().removeShutdownHook(getDubboShutdownHook());
  7. }
  8. }

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

  1. /** When true, <code>Runtime.getRuntime().halt(0);</code> is used when the JVM shuts down. This prevents Swing shutdown hooks
  2. * from causing a deadlock and keeping the JVM alive indefinitely. Default is true. */
  3. public void setHaltOnShutdown (boolean halt) {
  4. if (halt) {
  5. if (shutdownHook != null) return;
  6. shutdownHook = new Thread() {
  7. public void run () {
  8. Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
  9. }
  10. };
  11. Runtime.getRuntime().addShutdownHook(shutdownHook);
  12. } else if (shutdownHook != null) {
  13. Runtime.getRuntime().removeShutdownHook(shutdownHook);
  14. shutdownHook = null;
  15. }
  16. }

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

  1. /** When true, <code>Runtime.getRuntime().halt(0);</code> is used when the JVM shuts down. This prevents Swing shutdown hooks
  2. * from causing a deadlock and keeping the JVM alive indefinitely. Default is true. */
  3. public void setHaltOnShutdown (boolean halt) {
  4. if (halt) {
  5. if (shutdownHook != null) return;
  6. shutdownHook = new Thread() {
  7. public void run () {
  8. Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
  9. }
  10. };
  11. Runtime.getRuntime().addShutdownHook(shutdownHook);
  12. } else if (shutdownHook != null) {
  13. Runtime.getRuntime().removeShutdownHook(shutdownHook);
  14. shutdownHook = null;
  15. }
  16. }

代码示例来源:origin: stanfordnlp/CoreNLP

  1. /** Kills this process, and kills the stream gobblers waiting on it. */
  2. public void kill() {
  3. Runtime.getRuntime().removeShutdownHook(shutdownHoook);
  4. shutdownHoook.run();
  5. }

代码示例来源:origin: apache/incubator-dubbo

  1. /**
  2. * Unregister the ShutdownHook
  3. */
  4. public void unregister() {
  5. if (registered.get() && registered.compareAndSet(true, false)) {
  6. Runtime.getRuntime().removeShutdownHook(getDubboShutdownHook());
  7. }
  8. }

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

  1. /** When true, <code>Runtime.getRuntime().halt(0);</code> is used when the JVM shuts down. This prevents Swing shutdown hooks
  2. * from causing a deadlock and keeping the JVM alive indefinitely. Default is true. */
  3. public void setHaltOnShutdown (boolean halt) {
  4. if (halt) {
  5. if (shutdownHook != null) return;
  6. shutdownHook = new Thread() {
  7. public void run () {
  8. Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
  9. }
  10. };
  11. Runtime.getRuntime().addShutdownHook(shutdownHook);
  12. } else if (shutdownHook != null) {
  13. Runtime.getRuntime().removeShutdownHook(shutdownHook);
  14. shutdownHook = null;
  15. }
  16. }

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

  1. /** When true, <code>Runtime.getRuntime().halt(0);</code> is used when the JVM shuts down. This prevents Swing shutdown hooks
  2. * from causing a deadlock and keeping the JVM alive indefinitely. Default is true. */
  3. public void setHaltOnShutdown (boolean halt) {
  4. if (halt) {
  5. if (shutdownHook != null) return;
  6. shutdownHook = new Thread() {
  7. public void run () {
  8. Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
  9. }
  10. };
  11. Runtime.getRuntime().addShutdownHook(shutdownHook);
  12. } else if (shutdownHook != null) {
  13. Runtime.getRuntime().removeShutdownHook(shutdownHook);
  14. shutdownHook = null;
  15. }
  16. }

代码示例来源:origin: thinkaurelius/titan

  1. private synchronized void removeHook() {
  2. if (null == shutdownHook)
  3. return;
  4. ShutdownThread tmp = shutdownHook;
  5. shutdownHook = null;
  6. // Remove shutdown hook to avoid reference retention
  7. try {
  8. Runtime.getRuntime().removeShutdownHook(tmp);
  9. log.debug("Removed shutdown hook {}", tmp);
  10. } catch (IllegalStateException e) {
  11. log.warn("Failed to remove shutdown hook", e);
  12. }
  13. }

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

  1. @Override
  2. public boolean removeShutdownHook(Runnable shutdownHook) {
  3. Thread shutdownHookThread = null;
  4. if (!(shutdownHook instanceof Thread)) {
  5. shutdownHookThread = new Thread(shutdownHook);
  6. } else shutdownHookThread = (Thread) shutdownHook;
  7. return Runtime.getRuntime().removeShutdownHook(shutdownHookThread);
  8. }
  9. }

代码示例来源:origin: Netflix/zuul

  1. public void stop()
  2. {
  3. LOG.warn("Shutting down Zuul.");
  4. serverGroup.stop();
  5. // remove the shutdown hook that was added when the proxy was started, since it has now been stopped
  6. try {
  7. Runtime.getRuntime().removeShutdownHook(jvmShutdownHook);
  8. } catch (IllegalStateException e) {
  9. // ignore -- IllegalStateException means the VM is already shutting down
  10. }
  11. LOG.warn("Completed zuul shutdown.");
  12. }

代码示例来源:origin: spring-projects/spring-framework

  1. /**
  2. * Close this application context, destroying all beans in its bean factory.
  3. * <p>Delegates to {@code doClose()} for the actual closing procedure.
  4. * Also removes a JVM shutdown hook, if registered, as it's not needed anymore.
  5. * @see #doClose()
  6. * @see #registerShutdownHook()
  7. */
  8. @Override
  9. public void close() {
  10. synchronized (this.startupShutdownMonitor) {
  11. doClose();
  12. // If we registered a JVM shutdown hook, we don't need it anymore now:
  13. // We've already explicitly closed the context.
  14. if (this.shutdownHook != null) {
  15. try {
  16. Runtime.getRuntime().removeShutdownHook(this.shutdownHook);
  17. }
  18. catch (IllegalStateException ex) {
  19. // ignore - VM is already shutting down
  20. }
  21. }
  22. }
  23. }

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

  1. private void removeShutdownHook()
  2. {
  3. if ( shutdownHook != null )
  4. {
  5. if ( !Runtime.getRuntime().removeShutdownHook( shutdownHook ) )
  6. {
  7. log.warn( "Unable to remove shutdown hook" );
  8. }
  9. }
  10. }

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

  1. public synchronized void destroy() {
  2. running = false;
  3. if (executorService != null) {
  4. executorService.shutdown();
  5. }
  6. if (canalMQProducer != null) {
  7. canalMQProducer.stop();
  8. }
  9. if (shutdownThread != null) {
  10. Runtime.getRuntime().removeShutdownHook(shutdownThread);
  11. shutdownThread = null;
  12. }
  13. }

代码示例来源:origin: eclipse-vertx/vert.x

  1. /**
  2. * Close this file resolver, this is a blocking operation.
  3. */
  4. public void close() throws IOException {
  5. synchronized (this) {
  6. if (shutdownHook != null) {
  7. // May throw IllegalStateException if called from other shutdown hook so ignore that
  8. try {
  9. Runtime.getRuntime().removeShutdownHook(shutdownHook);
  10. } catch (IllegalStateException ignore) {
  11. }
  12. }
  13. }
  14. deleteCacheDir();
  15. }

代码示例来源:origin: Netflix/zuul

  1. public void stop()
  2. {
  3. LOG.warn("Shutting down Zuul.");
  4. serverGroup.stop();
  5. // remove the shutdown hook that was added when the proxy was started, since it has now been stopped
  6. try {
  7. Runtime.getRuntime().removeShutdownHook(jvmShutdownHook);
  8. } catch (IllegalStateException e) {
  9. // ignore -- IllegalStateException means the VM is already shutting down
  10. }
  11. LOG.warn("Completed zuul shutdown.");
  12. }

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

  1. @After
  2. public void tearDown() {
  3. Runtime.getRuntime().removeShutdownHook(logger.exitHook());
  4. }

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

  1. @Test
  2. public void shouldRegisterItselfAsExitHook() {
  3. logger = new SubprocessLogger(new DefaultCurrentProcess());
  4. logger.registerAsExitHook("foo");
  5. try {
  6. Runtime.getRuntime().addShutdownHook(logger.exitHook());
  7. } catch (IllegalArgumentException e) {
  8. assertThat(e.getMessage(), is("Hook previously registered"));
  9. } finally {
  10. Runtime.getRuntime().removeShutdownHook(logger.exitHook());
  11. }
  12. }
  13. }

相关文章