public void value(Callable<V> callable) { completionService.submit(callable); } });
public void value(Callable<T> callable) { completionService.submit(callable); } });
/** * Submit a task to the pool. */ public void submitTask(final Callable<Void> task) { Future<Void> f = this.taskPool.submit(task); futures.add(f); }
/** * Submit a task to the pool. * * NOTE: all must be submitted before you can safely {@link #waitForOutstandingTasks()}. This * version does not support issuing tasks from multiple concurrent table snapshots requests. */ void submitTask(final Callable<Void> task) { Future<Void> f = this.taskPool.submit(task); futures.add(f); }
/** * Submit a task to the pool. * * NOTE: all must be submitted before you can safely {@link #waitForOutstandingTasks()}. */ void submitTask(final Callable<Void> task) { Future<Void> f = this.taskPool.submit(task); futures.add(f); }
private void addRegionNode(final RegionStates stateMap, final TableName tableName, final long regionId) { executorService.submit(new Callable<Object>() { @Override public Object call() { return stateMap.getOrCreateRegionStateNode(RegionInfoBuilder.newBuilder(tableName) .setStartKey(Bytes.toBytes(regionId)) .setEndKey(Bytes.toBytes(regionId + 1)) .setSplit(false) .setRegionId(0) .build()); } }); }
ExecutorService executor = ...; ExecutorCompletionService ecs = new ExecutorCompletionService(executor); for (int i = 0; i < totalTasks; i++) { ... ecs.submit(...); ... } for (int i = 0; i < totalTasks; i++) { ecs.take(); }
public void submit(Runnable task) { Future future = comletions.submit(task, null); futures.add(future); check(future); }
public void submit(Callable<Exception> task) { Future future = comletions.submit(task); futures.add(future); check(future); }
public List<FutureType> submitTasksAndWait(List<? extends Callable<FutureType>> tasks) { List<Future<FutureType>> takes = Lists.newArrayList(tasks.size()); for (Callable<FutureType> callable : tasks) { takes.add(m_completionService.submit(callable)); } List<FutureType> result = Lists.newArrayList(takes.size()); for (Future<FutureType> take : takes) { try { result.add(take.get()); } catch (InterruptedException | ExecutionException e) { throw new TestNGException(e); } } m_executor.shutdown(); return result; } }
/** * Submit a task to the pool. */ public void submitTask(final Callable<Void> task) { Future<Void> f = this.taskPool.submit(task); futures.add(f); }
final ExecutorCompletionService<Void> completionService = new ExecutorCompletionService<>(exec); for (final RegionInfo hri: regions) { completionService.submit(new Callable<Void>() { @Override public Void call() throws IOException {
public List<FutureType> submitTasksAndWait(List<? extends Callable<FutureType>> tasks) { List<Future<FutureType>> takes = Lists.newArrayList(tasks.size()); for (Callable<FutureType> callable : tasks) { takes.add(m_completionService.submit(callable)); } List<FutureType> result = Lists.newArrayList(takes.size()); for (Future<FutureType> take : takes) { try { result.add(take.get()); } catch (InterruptedException | ExecutionException e) { // NOSONAR throw new TestNGException(e); } } m_executor.shutdown(); return result; } }
public void prepare(final StorableProperties properties) { ExecutorCompletionService completionService = new ExecutorCompletionService<>(threadPool); int counter = 0; for (final PrepareContractionHierarchies prepare : getPreparations()) { LOGGER.info((++counter) + "/" + getPreparations().size() + " calling CH prepare.doWork for " + prepare.getWeighting() + " ... (" + getMemInfo() + ")"); final String name = AbstractWeighting.weightingToFileName(prepare.getWeighting()); completionService.submit(new Runnable() { @Override public void run() { // toString is not taken into account so we need to cheat, see http://stackoverflow.com/q/6113746/194609 for other options Thread.currentThread().setName(name); prepare.doWork(); properties.put(CH.PREPARE + "date." + name, createFormatter().format(new Date())); } }, name); } threadPool.shutdown(); try { for (int i = 0; i < getPreparations().size(); i++) { completionService.take().get(); } } catch (Exception e) { threadPool.shutdownNow(); throw new RuntimeException(e); } }
@Test public void testSplitMainThreadLayouts() { SplitLayoutResolver.createForTag(splitTag, mMainConfig, mBgConfig, mEnabledComponent); SplitLayoutResolver resolver = SplitLayoutResolver.getForTag(splitTag); when(ThreadUtils.isMainThread()).thenReturn(true); Whitebox.setInternalState(resolver, "mainService", mainService); Whitebox.setInternalState(resolver, "bgService", bgService); ComponentTree tree = ComponentTree.create(mContext, mComponent).splitLayoutTag(splitTag).build(); tree.setRootAndSizeSpec( mComponent, makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY), new Size()); verify(mainService).submit(any(Runnable.class), eq(0)); verify(mainService).submit(any(Runnable.class), eq(1)); verify(mainService, never()).submit(any(Runnable.class), eq(2)); verify(bgService, never()).submit(any(Runnable.class), any()); }
@Test public void testSplitBgThreadLayouts() { SplitLayoutResolver.createForTag(splitTag, mMainConfig, mBgConfig, mEnabledComponent); SplitLayoutResolver resolver = SplitLayoutResolver.getForTag(splitTag); when(ThreadUtils.isMainThread()).thenReturn(false); Whitebox.setInternalState(resolver, "mainService", mainService); Whitebox.setInternalState(resolver, "bgService", bgService); final ComponentTree tree = ComponentTree.create(mContext, mComponent).splitLayoutTag(splitTag).build(); tree.setRootAndSizeSpecAsync( mComponent, makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY)); mLayoutThreadShadowLooper.runOneTask(); verify(bgService).submit(any(Runnable.class), eq(0)); verify(bgService).submit(any(Runnable.class), eq(1)); verify(bgService, never()).submit(any(Runnable.class), eq(2)); verify(mainService, never()).submit(any(Runnable.class), any()); }
private void warmUpPopulate(Map<Future<SubSingleBenchmarkRunner>, SubSingleBenchmarkRunner> futureMap, ConcurrentMap<SolverBenchmarkResult, Integer> singleBenchmarkResultIndexMap, SolverBenchmarkResult[] solverBenchmarkResultArray, long timeLeftPerSolverConfig) { for (SolverBenchmarkResult solverBenchmarkResult : solverBenchmarkResultArray) { TerminationConfig originalTerminationConfig = solverBenchmarkResult.getSolverConfig().getTerminationConfig(); TerminationConfig tmpTerminationConfig = new TerminationConfig(); if (originalTerminationConfig != null) { tmpTerminationConfig.inherit(originalTerminationConfig); } tmpTerminationConfig.shortenTimeMillisSpentLimit(timeLeftPerSolverConfig); solverBenchmarkResult.getSolverConfig().setTerminationConfig(tmpTerminationConfig); Integer singleBenchmarkResultIndex = singleBenchmarkResultIndexMap.get(solverBenchmarkResult); singleBenchmarkResultIndex = (singleBenchmarkResultIndex == null) ? 0 : singleBenchmarkResultIndex % solverBenchmarkResult.getSingleBenchmarkResultList().size(); SingleBenchmarkResult singleBenchmarkResult = solverBenchmarkResult.getSingleBenchmarkResultList().get(singleBenchmarkResultIndex); // Just take the first subSingle, we don't need to warm up each one SubSingleBenchmarkRunner subSingleBenchmarkRunner = new SubSingleBenchmarkRunner( singleBenchmarkResult.getSubSingleBenchmarkResultList().get(0), true, solverConfigContext); Future<SubSingleBenchmarkRunner> future = warmUpExecutorCompletionService.submit(subSingleBenchmarkRunner); futureMap.put(future, subSingleBenchmarkRunner); singleBenchmarkResultIndexMap.put(solverBenchmarkResult, singleBenchmarkResultIndex + 1); } }
@Test public void testMultipleClients() throws Exception { ExecutorService exec = Executors.newFixedThreadPool(NUM_THREADS); try { ExecutorCompletionService<Boolean> ecs = new ExecutorCompletionService<>(exec); for (int i = 0; i < NUM_THREADS; ++i) ecs.submit(new IdLockTestThread("client_" + i)); for (int i = 0; i < NUM_THREADS; ++i) { Future<Boolean> result = ecs.take(); assertTrue(result.get()); } idLock.assertMapEmpty(); } finally { exec.shutdown(); exec.awaitTermination(5000, TimeUnit.MILLISECONDS); } }
@Test public void testOnlyMainEnabled() { SplitLayoutResolver.createForTag(splitTag, mMainConfig, null, mEnabledComponent); SplitLayoutResolver resolver = SplitLayoutResolver.getForTag(splitTag); when(ThreadUtils.isMainThread()).thenReturn(false); Whitebox.setInternalState(resolver, "mainService", mainService); final ComponentTree tree = ComponentTree.create(mContext, mComponent).splitLayoutTag(splitTag).build(); tree.setRootAndSizeSpecAsync( mComponent, makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY)); mLayoutThreadShadowLooper.runOneTask(); verify(bgService, never()).submit(any(Runnable.class), eq(0)); } }
for ( int i = 0; i < numThreads; i++ ) ecs.submit( () ->