List of usage examples for com.google.common.util.concurrent MoreExecutors shutdownAndAwaitTermination
@Beta @GwtIncompatible("concurrency") public static boolean shutdownAndAwaitTermination(ExecutorService service, long timeout, TimeUnit unit)
From source file:javacommon.utils.Threads.java
/** * ExecutorService JavaDoc?Graceful Shutdown. * //from w w w . ja v a2s. c om * shutdown, ???. * * 1/2?, shutdownNow,?workQueuePending,. * * 1/2?. * * ?shutdown??. * * ??. */ public static boolean gracefulShutdown(ExecutorService threadPool, int shutdownTimeoutMills) { return MoreExecutors.shutdownAndAwaitTermination(threadPool, shutdownTimeoutMills, TimeUnit.MILLISECONDS); }
From source file:javacommon.utils.Threads.java
/** * @see #gracefulShutdown(ExecutorService, int) *///w w w.j ava 2 s . c o m public static boolean gracefulShutdown(ExecutorService threadPool, int shutdownTimeout, TimeUnit timeUnit) { return MoreExecutors.shutdownAndAwaitTermination(threadPool, shutdownTimeout, timeUnit); }
From source file:org.springside.modules.utils.concurrent.ThreadUtil.java
/** * ExecutorService JavaDoc?Graceful Shutdown. * //from w w w. j av a 2s .co m * shutdown, ???. * * 1/2?, shutdownNow,?workQueuePending,. * * 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) : true; }
From source file:org.springside.modules.utils.concurrent.ThreadUtil.java
/** * @see #gracefulShutdown(ExecutorService, int) *///from w ww. j a v a2s .c om public static boolean gracefulShutdown(@Nullable ExecutorService threadPool, int shutdownTimeout, TimeUnit timeUnit) { return threadPool != null ? MoreExecutors.shutdownAndAwaitTermination(threadPool, shutdownTimeout, timeUnit) : true; }
From source file:com.github.benmanes.caffeine.testing.Threads.java
public static void handleTimout(Queue<String> failures, ExecutorService es, TimeoutException e) { for (StackTraceElement[] trace : Thread.getAllStackTraces().values()) { for (StackTraceElement element : trace) { logger.info("\tat " + element); }// w w w. j ava 2s . co m if (trace.length > 0) { logger.info("------"); } } MoreExecutors.shutdownAndAwaitTermination(es, 10, TimeUnit.SECONDS); for (String failure : failures) { logger.debug(failure); } fail("Spun forever", e); }
From source file:org.vootoo.server.RequestExecutor.java
public boolean shutdownAndAwaitTermination(long timeout, TimeUnit unit) { return MoreExecutors.shutdownAndAwaitTermination(executorService, timeout, unit); }
From source file:org.immutables.mongo.fixture.MongoContext.java
private MongoContext(final MongoClient client) { Preconditions.checkNotNull(client, "client"); // allows to cleanup resources after each test final Closer closer = Closer.create(); closer.register(new Closeable() { @Override/* w w w . ja va 2 s . c om*/ public void close() throws IOException { client.close(); } }); // drop database if exists (to have a clean test) if (Iterables.contains(client.listDatabaseNames(), DBNAME)) { client.getDatabase(DBNAME).drop(); } this.database = client.getDatabase(DBNAME); closer.register(new Closeable() { @Override public void close() throws IOException { database.drop(); } }); final ListeningExecutorService executor = MoreExecutors .listeningDecorator(Executors.newSingleThreadExecutor()); closer.register(new Closeable() { @Override public void close() throws IOException { MoreExecutors.shutdownAndAwaitTermination(executor, 100, TimeUnit.MILLISECONDS); } }); this.setup = RepositorySetup.builder().gson(createGson()).executor(executor).database(database).build(); this.closer = closer; }
From source file:org.opendaylight.infrautils.utils.concurrent.Executors.java
public static void shutdownAndAwaitTermination(ExecutorService executorService) { MoreExecutors.shutdownAndAwaitTermination(executorService, DEFAULT_TIMEOUT_FOR_SHUTDOWN, DEFAULT_TIMEOUT_UNIT_FOR_SHUTDOWN); }
From source file:org.codice.ddf.catalog.sourcepoller.PollerRunner.java
/** Stops the {@link PollerRunner} and all {@link java.util.concurrent.ExecutorService}s */ public void destroy() { MoreExecutors.shutdownAndAwaitTermination(scheduledExecutorService, 5, TimeUnit.SECONDS); LOGGER.debug("Destroyed PollerRunner"); }
From source file:com.ignorelist.kassandra.steam.scraper.BatchTagLoader.java
public Map<Long, GameInfo> load(Collection<Long> gameIds, final EnumSet<TagType> types) { final UUID loadId = UUID.randomUUID(); final int total = gameIds.size(); long wallTimeStart = System.currentTimeMillis(); ExecutorService executorService = Executors.newFixedThreadPool(nThreads); final ConcurrentMap<Long, GameInfo> results = new ConcurrentHashMap<>(); final AtomicLong time = new AtomicLong(); final AtomicInteger current = new AtomicInteger(); for (final Long gameId : gameIds) { executorService.submit(new Runnable() { @Override//from w w w . ja v a2s . c o m public void run() { long start = System.currentTimeMillis(); GameInfo loaded = load(gameId, types); results.put(gameId, loaded); long end = System.currentTimeMillis(); final long duration = end - start; //System.err.println("loaded "+gameId+" in "+(end-start)+"ms"); time.addAndGet(duration); final int currentCount = current.incrementAndGet(); eventBus.post(new GameInfoLoadedEvent(loadId, currentCount, total, loaded, duration)); } }); } MoreExecutors.shutdownAndAwaitTermination(executorService, 1, TimeUnit.DAYS); long wallTimeEnd = System.currentTimeMillis(); System.err.println("finished loading " + total + " games"); System.err.println("time: " + time.longValue() + "ms"); System.err.println("wallTime: " + (wallTimeEnd - wallTimeStart) + "ms"); return results; }