com.google.common.util.concurrent.MoreExecutors#shutdownAndAwaitTermination ( )源码实例Demo

下面列出了com.google.common.util.concurrent.MoreExecutors#shutdownAndAwaitTermination ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: grpc-nebula-java   文件: TlsTest.java
@After
public void tearDown() {
  if (server != null) {
    server.shutdown();
  }
  if (channel != null) {
    channel.shutdown();
  }
  MoreExecutors.shutdownAndAwaitTermination(executor, 5, TimeUnit.SECONDS);
}
 
源代码2 项目: connector-sdk   文件: ListingConnector.java
@Override
public void destroy() {
  repository.close();
  repositoryContext.getEventBus().unregister(this);
  if (listeningExecutorService != null) {
    logger.log(Level.INFO, "Shutting down the executor service.");
    MoreExecutors.shutdownAndAwaitTermination(listeningExecutorService, 5L, TimeUnit.MINUTES);
  }
}
 
源代码3 项目: connector-sdk   文件: FullSyncIdentityConnector.java
/** Releases resources and shuts down worker processes. */
@Override
public void destroy() {
  identityRepository.close();
  try {
    stateManager.close();
  } catch (IOException e) {
    logger.log(Level.WARNING, "Failed to close identity state sucessfully", e);
  }
  if (listeningExecutorService != null) {
    MoreExecutors.shutdownAndAwaitTermination(listeningExecutorService, 5, TimeUnit.MINUTES);
  }
}
 
源代码4 项目: StubbornJava   文件: Http.java
public static void getInParallel(OkHttpClient client, String url, int count) {
    ExecutorService exec = Executors.newFixedThreadPool(count);
    for (int i = 0; i < count; i++) {
        exec.submit(() -> Http.get(client, url));
    }
    MoreExecutors.shutdownAndAwaitTermination(exec, 30, TimeUnit.SECONDS);
}
 
源代码5 项目: Singularity   文件: SingularitySmtpSender.java
@Override
public void stop() {
  if (mailSenderExecutorService.isPresent()) {
    MoreExecutors.shutdownAndAwaitTermination(
      mailSenderExecutorService.get(),
      1,
      TimeUnit.SECONDS
    );
  }
}
 
源代码6 项目: grpc-java   文件: TlsTest.java
@After
public void tearDown() {
  if (server != null) {
    server.shutdown();
  }
  if (channel != null) {
    channel.shutdown();
  }
  MoreExecutors.shutdownAndAwaitTermination(executor, 5, TimeUnit.SECONDS);
}
 
源代码7 项目: StubbornJava   文件: Http.java
public static void getInParallel(OkHttpClient client, String url, int count) {
    ExecutorService exec = Executors.newFixedThreadPool(count);
    for (int i = 0; i < count; i++) {
        exec.submit(() -> Http.get(client, url));
    }
    MoreExecutors.shutdownAndAwaitTermination(exec, 30, TimeUnit.SECONDS);
}
 
源代码8 项目: FastLogin   文件: AsyncScheduler.java
public void shutdown() {
    MoreExecutors.shutdownAndAwaitTermination(processingPool, 1, TimeUnit.MINUTES);
    //MoreExecutors.shutdownAndAwaitTermination(databaseExecutor, 1, TimeUnit.MINUTES);
}
 
源代码9 项目: helloiot   文件: CompletableAsync.java
public static void shutdown() {       
    MoreExecutors.shutdownAndAwaitTermination(service, 60, TimeUnit.SECONDS);
}
 
源代码10 项目: bazel   文件: MoreFuturesTest.java
@After
public final void shutdownExecutor() throws Exception  {
  MoreExecutors.shutdownAndAwaitTermination(executorService, TestUtils.WAIT_TIMEOUT_SECONDS,
      TimeUnit.SECONDS);

}
 
源代码11 项目: bazel   文件: ProcessRunnerTest.java
@AfterClass
public static void tearDownExecutor() {
  MoreExecutors.shutdownAndAwaitTermination(executorService, 5, TimeUnit.SECONDS);
}
 
源代码12 项目: connector-sdk   文件: StateManagerImpl.java
@Override
public void close() throws IOException {
  MoreExecutors.shutdownAndAwaitTermination(callbackExecutor, 5, TimeUnit.MINUTES);
  isRunning.set(false);
}
 
源代码13 项目: vjtools   文件: ThreadPoolUtil.java
/**
 * @see gracefulShutdown
 */
public static boolean gracefulShutdown(@Nullable ExecutorService threadPool, int shutdownTimeout,
		TimeUnit timeUnit) {
	return threadPool == null || MoreExecutors.shutdownAndAwaitTermination(threadPool, shutdownTimeout, timeUnit);
}
 
源代码14 项目: n4js   文件: ProjectStatePersister.java
/**
 * Close this persister and wait for pending write operations to complete.
 */
public void close() {
	MoreExecutors.shutdownAndAwaitTermination(writer, 5, TimeUnit.SECONDS);
}
 
源代码15 项目: n4js   文件: LSPExecutorService.java
/** An orderly shutdown of this executor service. */
public synchronized void shutdown() {
	MoreExecutors.shutdownAndAwaitTermination(delegate, 2500, TimeUnit.MILLISECONDS);
	cancelAll();
}
 
源代码16 项目: bazel   文件: BlackBoxTestEnvironment.java
/**
 * This method must be called when the test group execution is finished, for example, from
 * &#64;AfterClass method.
 */
public final void dispose() {
  Preconditions.checkNotNull(executorService);
  MoreExecutors.shutdownAndAwaitTermination(executorService, 1, TimeUnit.SECONDS);
  executorService = null;
}
 
源代码17 项目: feeyo-redisproxy   文件: ThreadPoolUtil.java
/**
 * @see gracefulShutdown
 */
public static boolean gracefulShutdown( ExecutorService threadPool, int shutdownTimeout,
		TimeUnit timeUnit) {
	return threadPool == null || MoreExecutors.shutdownAndAwaitTermination(threadPool, shutdownTimeout, timeUnit);
}
 
源代码18 项目: bazel   文件: DexFileMerger.java
@VisibleForTesting
static void buildMergedDexFiles(Options options) throws IOException {
  ListeningExecutorService executor;
  checkArgument(!options.inputArchives.isEmpty(), "Need at least one --input");
  checkArgument(
      options.mainDexListFile == null || options.inputArchives.size() == 1,
      "--main-dex-list only supported with exactly one --input, use DexFileSplitter for more");
  if (options.multidexMode.isMultidexAllowed()) {
    executor = createThreadPool();
  } else {
    checkArgument(
        options.mainDexListFile == null,
        "--main-dex-list is only supported with multidex enabled, but mode is: %s",
        options.multidexMode);
    checkArgument(
        !options.minimalMainDex,
        "--minimal-main-dex is only supported with multidex enabled, but mode is: %s",
        options.multidexMode);
    // We'll only ever merge and write one dex file, so multi-threading is pointless.
    executor = MoreExecutors.newDirectExecutorService();
  }

  ImmutableSet<String> classesInMainDex = options.mainDexListFile != null
      ? ImmutableSet.copyOf(Files.readAllLines(options.mainDexListFile, UTF_8))
      : null;
  PrintStream originalStdOut = System.out;
  try (DexFileAggregator out = createDexFileAggregator(options, executor)) {
    if (!options.verbose) {
      // com.android.dx.merge.DexMerger prints status information to System.out that we silence
      // here unless it was explicitly requested.  (It also prints debug info to DxContext.out,
      // which we populate accordingly below.)
      System.setOut(Dexing.nullout);
    }

    LinkedHashSet<String> seen = new LinkedHashSet<>();
    for (Path inputArchive : options.inputArchives) {
      // Simply merge files from inputs in order.  Doing that with a main dex list doesn't work,
      // but we rule out more than one input with a main dex list above.
      try (ZipFile zip = new ZipFile(inputArchive.toFile())) {
        ArrayList<ZipEntry> dexFiles = filesToProcess(zip);
        if (classesInMainDex == null) {
          processDexFiles(zip, dexFiles, seen, out);
        } else {
          // To honor --main_dex_list make two passes:
          // 1. process only the classes listed in the given file
          // 2. process the remaining files
          Predicate<ZipEntry> mainDexFilter =
              ZipEntryPredicates.classFileFilter(classesInMainDex);
          processDexFiles(zip, Iterables.filter(dexFiles, mainDexFilter), seen, out);
          // Fail if main_dex_list is too big, following dx's example
          checkState(out.getDexFilesWritten() == 0, "Too many classes listed in main dex list "
              + "file %s, main dex capacity exceeded", options.mainDexListFile);
          if (options.minimalMainDex) {
            out.flush(); // Start new .dex file if requested
          }
          processDexFiles(
              zip, Iterables.filter(dexFiles, Predicates.not(mainDexFilter)), seen, out);
        }
      }
    }
  } finally {
    // Kill threads in the pool so we don't hang
    MoreExecutors.shutdownAndAwaitTermination(executor, 1, SECONDS);
    System.setOut(originalStdOut);
  }
}
 
源代码19 项目: caffeine   文件: Issue30Test.java
@AfterClass
public void afterClass() {
  MoreExecutors.shutdownAndAwaitTermination(executor, 1, TimeUnit.MINUTES);
}
 
源代码20 项目: vjtools   文件: ThreadPoolUtil.java
/**
 * 按照ExecutorService JavaDoc示例代码编写的Graceful Shutdown方法.
 * 
 * 先使用shutdown, 停止接收新任务并尝试完成所有已存在任务.
 * 
 * 如果1/2超时时间后, 则调用shutdownNow,取消在workQueue中Pending的任务,并中断所有阻塞函数.
 * 
 * 如果1/2超时仍然超時,則強制退出.
 * 
 * 另对在shutdown时线程本身被调用中断做了处理.
 * 
 * 返回线程最后是否被中断.
 * 
 * 使用了Guava的工具类
 * @see MoreExecutors#shutdownAndAwaitTermination(ExecutorService, long, TimeUnit)
 */
public static boolean gracefulShutdown(@Nullable ExecutorService threadPool, int shutdownTimeoutMills) {
	return threadPool == null
			|| MoreExecutors.shutdownAndAwaitTermination(threadPool, shutdownTimeoutMills, TimeUnit.MILLISECONDS);
}