org.apache.tomcat.util.threads.ThreadPoolExecutor.awaitTermination()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(3.5k)|赞(0)|评价(0)|浏览(126)

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

ThreadPoolExecutor.awaitTermination介绍

暂无

代码示例

代码示例来源:origin: testIT-LivingDoc/livingdoc-core

@Override
public void onApplicationEvent(ContextClosedEvent event) {
  this.connector.pause();
  log.info("Shutting Down LivingDoc Remote Agent");
  Executor executor = this.connector.getProtocolHandler().getExecutor();
  if (executor instanceof ThreadPoolExecutor) {
    try {
      ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
      threadPoolExecutor.shutdown();
      if (!threadPoolExecutor.awaitTermination(30, TimeUnit.SECONDS)) {
        log.warn("Tomcat thread pool did not shut down gracefully within "
            + "30 seconds. Proceeding with forceful shutdown");
      }
    } catch (InterruptedException ex) {
      Thread.currentThread().interrupt();
    }
  }
}

代码示例来源:origin: corentin59/spring-boot-graceful-shutdown

/**
 * Perform a shutdown
 * @param delay is delay to force is the delay before perform a force shutdown
 * @throws InterruptedException if we have an exception
 */
public void shutdown(Integer delay) throws InterruptedException {
  // Used to properly handle the work queue.
  final Executor executor = connector.getProtocolHandler().getExecutor();
  final ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor) executor;
  /*
   * Initiates an orderly shutdown in which previously submitted
   * tasks are executed, but no new tasks will be accepted.
   * Invocation has no additional effect if already shut down.
   */
  threadPoolExecutor.shutdown();
  // We wait after the end of the current requests
  if(!threadPoolExecutor.awaitTermination(delay, TimeUnit.SECONDS)) {
    logger.warn("Tomcat thread pool did not shut down gracefully within " + delay + " second(s). Proceeding with force shutdown");
  } else {
    logger.debug("Tomcat thread pool is empty, we stop now");
  }
}

代码示例来源:origin: lord-of-code/loc-framework

threadPoolExecutor.shutdown();
if (!threadPoolExecutor
  .awaitTermination(tomcatGracefulShutdownProperties.getWaitTime(), TimeUnit.SECONDS)) {
 log.warn("Tomcat thread pool did not shut down gracefully within "
   + tomcatGracefulShutdownProperties

代码示例来源:origin: codefollower/Tomcat-Research

public void shutdownExecutor() {
  if ( executor!=null && internalExecutor ) {
    if ( executor instanceof ThreadPoolExecutor ) {
      //this is our internal one, so we need to shut it down
      ThreadPoolExecutor tpe = (ThreadPoolExecutor) executor;
      tpe.shutdownNow();
      long timeout = getExecutorTerminationTimeoutMillis();
      if (timeout > 0) {
        try {
          tpe.awaitTermination(timeout, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
          // Ignore
        }
        if (tpe.isTerminating()) {
          getLog().warn(sm.getString("endpoint.warn.executorShutdown", getName()));
        }
      }
      TaskQueue queue = (TaskQueue) tpe.getQueue();
      queue.setParent(null);
    }
    executor = null;
  }
}

代码示例来源:origin: org.ops4j.pax.tipi/org.ops4j.pax.tipi.tomcat-embed-core

public void shutdownExecutor() {
  Executor executor = this.executor;
  if (executor != null && internalExecutor) {
    this.executor = null;
    if (executor instanceof ThreadPoolExecutor) {
      //this is our internal one, so we need to shut it down
      ThreadPoolExecutor tpe = (ThreadPoolExecutor) executor;
      tpe.shutdownNow();
      long timeout = getExecutorTerminationTimeoutMillis();
      if (timeout > 0) {
        try {
          tpe.awaitTermination(timeout, TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
          // Ignore
        }
        if (tpe.isTerminating()) {
          getLog().warn(sm.getString("endpoint.warn.executorShutdown", getName()));
        }
      }
      TaskQueue queue = (TaskQueue) tpe.getQueue();
      queue.setParent(null);
    }
  }
}

相关文章