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

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

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

public void removeShutdownHook() {
  if (shutDownHook != null) {
    Runtime.getRuntime().removeShutdownHook(shutDownHook);
  }
}

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

private void removeShutdownHook(Shutdown shutdownHook) {
  try {
    Runtime.getRuntime().removeShutdownHook(shutdownHook);
  } catch (Exception e) {
  }
}

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

private void removeShutDownHook(Thread shutdownHook) {
  if (shutdownHook != null) {
    try {
      Runtime.getRuntime().removeShutdownHook(shutdownHook);
    } catch (Exception e) {
    }
  }
}

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

/**
 * Unregister the ShutdownHook
 */
public void unregister() {
  if (registered.get() && registered.compareAndSet(true, false)) {
    Runtime.getRuntime().removeShutdownHook(getDubboShutdownHook());
  }
}

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

/** When true, <code>Runtime.getRuntime().halt(0);</code> is used when the JVM shuts down. This prevents Swing shutdown hooks
 * from causing a deadlock and keeping the JVM alive indefinitely. Default is true. */
public void setHaltOnShutdown (boolean halt) {
  if (halt) {
    if (shutdownHook != null) return;
    shutdownHook = new Thread() {
      public void run () {
        Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
      }
    };
    Runtime.getRuntime().addShutdownHook(shutdownHook);
  } else if (shutdownHook != null) {
    Runtime.getRuntime().removeShutdownHook(shutdownHook);
    shutdownHook = null;
  }
}

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

/** When true, <code>Runtime.getRuntime().halt(0);</code> is used when the JVM shuts down. This prevents Swing shutdown hooks
 * from causing a deadlock and keeping the JVM alive indefinitely. Default is true. */
public void setHaltOnShutdown (boolean halt) {
  if (halt) {
    if (shutdownHook != null) return;
    shutdownHook = new Thread() {
      public void run () {
        Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
      }
    };
    Runtime.getRuntime().addShutdownHook(shutdownHook);
  } else if (shutdownHook != null) {
    Runtime.getRuntime().removeShutdownHook(shutdownHook);
    shutdownHook = null;
  }
}

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

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

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

/**
 * Unregister the ShutdownHook
 */
public void unregister() {
  if (registered.get() && registered.compareAndSet(true, false)) {
    Runtime.getRuntime().removeShutdownHook(getDubboShutdownHook());
  }
}

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

/** When true, <code>Runtime.getRuntime().halt(0);</code> is used when the JVM shuts down. This prevents Swing shutdown hooks
 * from causing a deadlock and keeping the JVM alive indefinitely. Default is true. */
public void setHaltOnShutdown (boolean halt) {
  if (halt) {
    if (shutdownHook != null) return;
    shutdownHook = new Thread() {
      public void run () {
        Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
      }
    };
    Runtime.getRuntime().addShutdownHook(shutdownHook);
  } else if (shutdownHook != null) {
    Runtime.getRuntime().removeShutdownHook(shutdownHook);
    shutdownHook = null;
  }
}

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

/** When true, <code>Runtime.getRuntime().halt(0);</code> is used when the JVM shuts down. This prevents Swing shutdown hooks
 * from causing a deadlock and keeping the JVM alive indefinitely. Default is true. */
public void setHaltOnShutdown (boolean halt) {
  if (halt) {
    if (shutdownHook != null) return;
    shutdownHook = new Thread() {
      public void run () {
        Runtime.getRuntime().halt(0); // Because fuck you, deadlock causing Swing shutdown hooks.
      }
    };
    Runtime.getRuntime().addShutdownHook(shutdownHook);
  } else if (shutdownHook != null) {
    Runtime.getRuntime().removeShutdownHook(shutdownHook);
    shutdownHook = null;
  }
}

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

private synchronized void removeHook() {
  if (null == shutdownHook)
      return;
  ShutdownThread tmp = shutdownHook;
  shutdownHook = null;
  // Remove shutdown hook to avoid reference retention
  try {
    Runtime.getRuntime().removeShutdownHook(tmp);
    log.debug("Removed shutdown hook {}", tmp);
  } catch (IllegalStateException e) {
    log.warn("Failed to remove shutdown hook", e);
  }
}

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

@Override
 public boolean removeShutdownHook(Runnable shutdownHook) {
  Thread shutdownHookThread = null;
  if (!(shutdownHook instanceof Thread)) {
   shutdownHookThread = new Thread(shutdownHook);
  } else shutdownHookThread = (Thread) shutdownHook;
  return Runtime.getRuntime().removeShutdownHook(shutdownHookThread);
 }
}

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

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

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

/**
 * Close this application context, destroying all beans in its bean factory.
 * <p>Delegates to {@code doClose()} for the actual closing procedure.
 * Also removes a JVM shutdown hook, if registered, as it's not needed anymore.
 * @see #doClose()
 * @see #registerShutdownHook()
 */
@Override
public void close() {
  synchronized (this.startupShutdownMonitor) {
    doClose();
    // If we registered a JVM shutdown hook, we don't need it anymore now:
    // We've already explicitly closed the context.
    if (this.shutdownHook != null) {
      try {
        Runtime.getRuntime().removeShutdownHook(this.shutdownHook);
      }
      catch (IllegalStateException ex) {
        // ignore - VM is already shutting down
      }
    }
  }
}

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

private void removeShutdownHook()
{
  if ( shutdownHook != null )
  {
    if ( !Runtime.getRuntime().removeShutdownHook( shutdownHook ) )
    {
      log.warn( "Unable to remove shutdown hook" );
    }
  }
}

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

public synchronized void destroy() {
  running = false;
  if (executorService != null) {
    executorService.shutdown();
  }
  if (canalMQProducer != null) {
    canalMQProducer.stop();
  }
  if (shutdownThread != null) {
    Runtime.getRuntime().removeShutdownHook(shutdownThread);
    shutdownThread = null;
  }
}

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

/**
 * Close this file resolver, this is a blocking operation.
 */
public void close() throws IOException {
 synchronized (this) {
  if (shutdownHook != null) {
   // May throw IllegalStateException if called from other shutdown hook so ignore that
   try {
    Runtime.getRuntime().removeShutdownHook(shutdownHook);
   } catch (IllegalStateException ignore) {
   }
  }
 }
 deleteCacheDir();
}

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

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

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

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

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

@Test
  public void shouldRegisterItselfAsExitHook() {
    logger = new SubprocessLogger(new DefaultCurrentProcess());
    logger.registerAsExitHook("foo");
    try {
      Runtime.getRuntime().addShutdownHook(logger.exitHook());
    } catch (IllegalArgumentException e) {
      assertThat(e.getMessage(), is("Hook previously registered"));
    } finally {
      Runtime.getRuntime().removeShutdownHook(logger.exitHook());
    }
  }
}

相关文章