java.util.concurrent.ThreadPoolExecutor.shutdownNow()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(5.3k)|赞(0)|评价(0)|浏览(170)

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

ThreadPoolExecutor.shutdownNow介绍

[英]Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution. These tasks are drained (removed) from the task queue upon return from this method.

This method does not wait for actively executing tasks to terminate. Use #awaitTermination to do that.

There are no guarantees beyond best-effort attempts to stop processing actively executing tasks. This implementation cancels tasks via Thread#interrupt, so any task that fails to respond to interrupts may never terminate.
[中]尝试停止所有正在执行的任务,停止正在等待的任务的处理,并返回正在等待执行的任务的列表。从该方法返回时,这些任务将从任务队列中排出(删除)。
此方法不会等待主动执行的任务终止。使用#等待终止来完成。
除了尽最大努力停止处理积极执行的任务之外,没有其他保证。此实现通过线程中断取消任务,因此任何未能响应中断的任务可能永远不会终止。

代码示例

代码示例来源:origin: org.testng/testng

@Override
public void stopNow() {
  super.shutdownNow();
 }

代码示例来源:origin: skylot/jadx

@Override
  public boolean cancel(boolean mayInterruptIfRunning) {
    executor.shutdownNow();
    return super.cancel(mayInterruptIfRunning);
  }
}

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

private void interrupt() {
 longCompactions.shutdownNow();
 shortCompactions.shutdownNow();
}

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

/**
 * Cleanly shutdown
 */
public void shutdown() {
 executor.shutdownNow();
}

代码示例来源:origin: xuxueli/xxl-job

public void stop() {
  //triggerPool.shutdown();
  triggerPool.shutdownNow();
  logger.info(">>>>>>>>> xxl-job trigger thread pool shutdown success.");
}

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

@Override
public void abort(String why, Throwable e) {
 if (this.aborted) {
  return;
 }
 this.aborted = true;
 LOG.warn("Aborting because: " + why, e);
 this.executor.shutdownNow();
}

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

private void cancelScheduledTasks() {
  if (instanceInfoReplicator != null) {
    instanceInfoReplicator.stop();
  }
  if (heartbeatExecutor != null) {
    heartbeatExecutor.shutdownNow();
  }
  if (cacheRefreshExecutor != null) {
    cacheRefreshExecutor.shutdownNow();
  }
  if (scheduler != null) {
    scheduler.shutdownNow();
  }
}

代码示例来源:origin: Justson/AgentWeb

private void internalInit() {
  if (mThreadPoolExecutor != null && !mThreadPoolExecutor.isShutdown()) {
    mThreadPoolExecutor.shutdownNow();
  }
  mThreadPoolExecutor = new ThreadPoolExecutor(
      CORE_POOL_SIZE, MAXIMUM_POOL_SIZE, KEEP_ALIVE_SECONDS, TimeUnit.SECONDS,
      sPoolWorkQueue, sThreadFactory);
  mThreadPoolExecutor.allowCoreThreadTimeOut(true);
}

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

@Override
  public void close() throws Exception {
    processor.shutdown();
    processor.awaitTermination(shutdownWaitMS,TimeUnit.MILLISECONDS);
    if (!processor.isTerminated()) {
      //log.error("Processor did not terminate in time");
      processor.shutdownNow();
    }

  }
}

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

public boolean stop() {
 if (!running.getAndSet(false)) {
  return false;
 }
 LOG.info("Stopping procedure remote dispatcher");
 // send stop signals
 timeoutExecutor.sendStopSignal();
 threadPool.shutdownNow();
 return true;
}

代码示例来源:origin: aa112901/remusic

public static void finish() {
    if(mInstance != null){
      mInstance.mThreadPoolExec.shutdownNow();
      mInstance.mThreadPoolExec.purge();
      mInstance.mThreadPoolExec = null;
      mInstance = null;
    }
  }
}

代码示例来源:origin: JanusGraph/janusgraph

@Override
  public void close() throws Exception {
    processor.shutdown();
    processor.awaitTermination(SHUTDOWN_WAIT_MS,TimeUnit.MILLISECONDS);
    if (!processor.isTerminated()) {
      //log.error("Processor did not terminate in time");
      processor.shutdownNow();
    }

  }
}

代码示例来源:origin: lingochamp/FileDownloader

public void expireAll() {
  if (FileDownloadLog.NEED_LOG) {
    FileDownloadLog.d(this, "expire %d tasks",
        mWorkQueue.size());
  }
  mPool.shutdownNow();
  init();
}

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

@Override
public void shutdownExecutor() {
  List<Runnable> remainingTasks = concurrentExecutor.shutdownNow();
  for (Runnable task : remainingTasks) {
    if (task instanceof RunnableFuture) {
      ((RunnableFuture<?>) task).cancel(true);
    }
  }
}

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

@Override
public void abort(String why, Throwable e) {
 if (this.aborted) return;
 this.aborted = true;
 LOG.warn("Aborting because: " + why, e);
 this.executor.shutdownNow();
}

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

@Override
public void shutdown() {
  if(Monitors.isObjectRegistered(name, this)) {
    Monitors.unregisterObject(name, this);
  }
  executorService.shutdownNow();
  threadPoolExecutor.shutdownNow();
  backgroundTask.cancel();
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public void shutDown() {
  try {
    threadPoolExecutor.shutdownNow();
    LOGGER.info("stop working succeed ");
  } catch (Throwable t) {
    LOGGER.error("stop working failed ", t);
  }
}

代码示例来源:origin: ltsopensource/light-task-scheduler

public void shutDown() {
  try {
    threadPoolExecutor.shutdownNow();
    LOGGER.info("stop working succeed ");
  } catch (Throwable t) {
    LOGGER.error("stop working failed ", t);
  }
}

代码示例来源:origin: ethereum/ethereumj

private void shutdownAsyncGroup() {
  traversalQueue.clear();
  traversalExecutor.shutdownNow();
  try {
    traversalExecutor.awaitTermination(60, TimeUnit.MINUTES);
  } catch (InterruptedException e) {
    logger.error("Validating nodes: traversal has been interrupted", e);
    throw new RuntimeException("Traversal has been interrupted", e);
  }
}

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

@After
public void tearDown() {
  if (executor != null) {
    executor.shutdownNow();
  }
  if (helperExecutor != null) {
    helperExecutor.shutdownNow();
  }
  if (scheduler != null) {
    scheduler.shutdownNow();
  }
}

相关文章

ThreadPoolExecutor类方法