use of java.util.concurrent.ForkJoinPool in project buck by facebook.
the class TargetGraphHashing method hashTargetGraph.
/**
* Given a {@link TargetGraph} and any number of root nodes to traverse,
* returns a map of {@code (BuildTarget, HashCode)} pairs for all root
* build targets and their dependencies.
*/
public ImmutableMap<BuildTarget, HashCode> hashTargetGraph() throws CycleException {
try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(eventBus, PerfEventId.of("ShowTargetHashes"))) {
AcyclicDepthFirstPostOrderTraversal<TargetNode<?, ?>> traversal = new AcyclicDepthFirstPostOrderTraversal<>(node -> targetGraph.getAll(node.getDeps()).iterator());
final Map<BuildTarget, ForkJoinTask<HashCode>> buildTargetHashes = new HashMap<>();
Queue<ForkJoinTask<HashCode>> tasksToSchedule = new ArrayDeque<>();
// Start all the node tasks, bottom up
for (final TargetNode<?, ?> node : traversal.traverse(roots)) {
HashNodeTask task = new HashNodeTask(node, buildTargetHashes);
buildTargetHashes.put(node.getBuildTarget(), task);
tasksToSchedule.add(task);
}
// Execute tasks in parallel
ForkJoinPool pool = new ForkJoinPool(numThreads);
for (ForkJoinTask<HashCode> task : tasksToSchedule) {
pool.execute(task);
}
// Wait for all scheduled tasks to complete
return ImmutableMap.copyOf(Maps.transformEntries(buildTargetHashes, (key, value) -> value.join()));
}
}
use of java.util.concurrent.ForkJoinPool in project buck by facebook.
the class PythonLibraryDescriptionTest method versionedResources.
@Test
public void versionedResources() throws Exception {
BuildTarget target = BuildTargetFactory.newInstance("//foo:lib");
SourcePath matchedSource = new FakeSourcePath("foo/a.py");
SourcePath unmatchedSource = new FakeSourcePath("foo/b.py");
GenruleBuilder transitiveDepBuilder = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:tdep")).setOut("out");
VersionedAliasBuilder depBuilder = new VersionedAliasBuilder(BuildTargetFactory.newInstance("//:dep")).setVersions(ImmutableMap.of(Version.of("1.0"), transitiveDepBuilder.getTarget(), Version.of("2.0"), transitiveDepBuilder.getTarget()));
AbstractNodeBuilder<?, ?, ?> builder = new PythonLibraryBuilder(target).setVersionedResources(VersionMatchedCollection.<SourceList>builder().add(ImmutableMap.of(depBuilder.getTarget(), Version.of("1.0")), SourceList.ofUnnamedSources(ImmutableSortedSet.of(matchedSource))).add(ImmutableMap.of(depBuilder.getTarget(), Version.of("2.0")), SourceList.ofUnnamedSources(ImmutableSortedSet.of(unmatchedSource))).build());
TargetGraph targetGraph = VersionedTargetGraphBuilder.transform(new FixedVersionSelector(ImmutableMap.of(builder.getTarget(), ImmutableMap.of(depBuilder.getTarget(), Version.of("1.0")))), TargetGraphAndBuildTargets.of(TargetGraphFactory.newInstance(transitiveDepBuilder.build(), depBuilder.build(), builder.build()), ImmutableSet.of(builder.getTarget())), new ForkJoinPool()).getTargetGraph();
BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
PythonLibrary library = (PythonLibrary) resolver.requireRule(builder.getTarget());
assertThat(library.getPythonPackageComponents(PythonTestUtils.PYTHON_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORM).getResources().values(), Matchers.contains(matchedSource));
}
use of java.util.concurrent.ForkJoinPool in project buck by facebook.
the class VersionedTargetGraphCacheTest method testPoolChangeCausesHit.
@Test
public void testPoolChangeCausesHit() throws Exception {
VersionedTargetGraphCache cache = new VersionedTargetGraphCache();
TargetGraphAndBuildTargets graph = createSimpleGraph();
VersionedTargetGraphCacheResult firstResult = cache.getVersionedTargetGraph(BUS, graph, ImmutableMap.of(), POOL);
assertEmpty(firstResult);
VersionedTargetGraphCacheResult secondResult = cache.getVersionedTargetGraph(BUS, graph, ImmutableMap.of(), new ForkJoinPool(2));
assertHit(secondResult, firstResult.getTargetGraphAndBuildTargets());
}
use of java.util.concurrent.ForkJoinPool in project torodb by torodb.
the class DefaultConcurrentToolsFactory method createExecutorService.
@Override
@SuppressFBWarnings(value = { "NP_NONNULL_PARAM_VIOLATION" }, justification = "ForkJoinPool constructor admits a null " + "UncaughtExceptionHandler")
public ExecutorService createExecutorService(String prefix, boolean blockerTasks, int maxThreads) {
ExecutorService executorService;
if (blockerTasks) {
ThreadFactory threadFactory = blockerThreadFactoryFunction.apply(prefix);
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(maxThreads, maxThreads, 10L, TimeUnit.MINUTES, new LinkedBlockingQueue<>(), threadFactory);
threadPoolExecutor.allowCoreThreadTimeOut(true);
executorService = threadPoolExecutor;
} else {
ForkJoinWorkerThreadFactory threadFactory = forkJoinThreadFactoryFunction.apply(prefix);
executorService = new ForkJoinPool(maxThreads, threadFactory, null, true);
}
shutdownHelper.terminateOnShutdown(prefix, executorService);
return executorService;
}
use of java.util.concurrent.ForkJoinPool in project jdk8u_jdk by JetBrains.
the class NQueensCS method main.
/**
* Usage: NQueensCS [minBoardSize=N] [maxBoardSize=N] [procs=N] [reps=N]
*/
public static void main(String[] args) throws Exception {
// Board sizes too small: hard to measure well.
// Board sizes too large: take too long to run.
final int minBoardSize = intArg(args, "minBoardSize", 8);
final int maxBoardSize = intArg(args, "maxBoardSize", 15);
final int procs = intArg(args, "procs", 0);
for (int reps = intArg(args, "reps", 10); reps > 0; reps--) {
ForkJoinPool g = (procs == 0) ? new ForkJoinPool() : new ForkJoinPool(procs);
lastStealCount = g.getStealCount();
for (int i = minBoardSize; i <= maxBoardSize; i++) test(g, i);
System.out.println(g);
g.shutdown();
}
}
Aggregations