Search in sources :

Example 6 with ForkJoinPool

use of java.util.concurrent.ForkJoinPool in project hadoop by apache.

the class FSDirectory method updateCountForQuota.

/**
   * Update the count of each directory with quota in the namespace.
   * A directory's count is defined as the total number inodes in the tree
   * rooted at the directory.
   *
   * This is an update of existing state of the filesystem and does not
   * throw QuotaExceededException.
   */
void updateCountForQuota(int initThreads) {
    writeLock();
    try {
        int threads = (initThreads < 1) ? 1 : initThreads;
        LOG.info("Initializing quota with " + threads + " thread(s)");
        long start = Time.now();
        QuotaCounts counts = new QuotaCounts.Builder().build();
        ForkJoinPool p = new ForkJoinPool(threads);
        RecursiveAction task = new InitQuotaTask(getBlockStoragePolicySuite(), rootDir.getStoragePolicyID(), rootDir, counts);
        p.execute(task);
        task.join();
        p.shutdown();
        LOG.info("Quota initialization completed in " + (Time.now() - start) + " milliseconds\n" + counts);
    } finally {
        writeUnlock();
    }
}
Also used : RecursiveAction(java.util.concurrent.RecursiveAction) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 7 with ForkJoinPool

use of java.util.concurrent.ForkJoinPool in project buck by facebook.

the class PythonLibraryDescriptionTest method versionedSrcs.

@Test
public void versionedSrcs() 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).setVersionedSrcs(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).getModules().values(), Matchers.contains(matchedSource));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) TargetGraph(com.facebook.buck.rules.TargetGraph) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) CxxGenruleBuilder(com.facebook.buck.cxx.CxxGenruleBuilder) FixedVersionSelector(com.facebook.buck.versions.FixedVersionSelector) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) VersionedAliasBuilder(com.facebook.buck.versions.VersionedAliasBuilder) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) BuildTarget(com.facebook.buck.model.BuildTarget) SourceList(com.facebook.buck.rules.coercer.SourceList) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) ForkJoinPool(java.util.concurrent.ForkJoinPool) Test(org.junit.Test)

Example 8 with ForkJoinPool

use of java.util.concurrent.ForkJoinPool in project jdk8u_jdk by JetBrains.

the class Integrate method main.

/**
     * Usage: Integrate [procs=N] [reps=N] forkPolicy=serial|dynamic|fork
     */
public static void main(String[] args) throws Exception {
    final int procs = intArg(args, "procs", Runtime.getRuntime().availableProcessors());
    final int forkPolicy = policyArg(args, "forkPolicy", DYNAMIC);
    ForkJoinPool g = new ForkJoinPool(procs);
    System.out.println("Integrating from " + start + " to " + end + " forkPolicy = " + forkPolicy);
    long lastTime = System.nanoTime();
    for (int reps = intArg(args, "reps", 10); reps > 0; reps--) {
        double a;
        if (forkPolicy == SERIAL)
            a = SQuad.computeArea(g, start, end);
        else if (forkPolicy == FORK)
            a = FQuad.computeArea(g, start, end);
        else
            a = DQuad.computeArea(g, start, end);
        long now = System.nanoTime();
        double s = (double) (now - lastTime) / NPS;
        lastTime = now;
        System.out.printf("Calls/sec: %12d", (long) (calls / s));
        System.out.printf(" Time: %7.3f", s);
        System.out.printf(" Area: %12.1f", a);
        System.out.println();
    }
    System.out.println(g);
    g.shutdown();
}
Also used : ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 9 with ForkJoinPool

use of java.util.concurrent.ForkJoinPool in project jdk8u_jdk by JetBrains.

the class SubmissionTest method main.

public static void main(String[] args) throws Throwable {
    final ForkJoinPool e = new ForkJoinPool(1);
    final AtomicBoolean b = new AtomicBoolean();
    final Runnable setFalse = () -> b.set(false);
    for (int i = 0; i < 100000; i++) {
        b.set(true);
        e.execute(setFalse);
        long st = System.nanoTime();
        while (b.get()) {
            if (System.nanoTime() - st >= TimeUnit.SECONDS.toNanos(10)) {
                throw new RuntimeException("Submitted task failed to execute");
            }
        }
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ForkJoinPool(java.util.concurrent.ForkJoinPool)

Example 10 with ForkJoinPool

use of java.util.concurrent.ForkJoinPool in project java8-tutorial by winterbe.

the class Streams12 method test1.

private static void test1() {
    // -Djava.util.concurrent.ForkJoinPool.common.parallelism=5
    ForkJoinPool commonPool = ForkJoinPool.commonPool();
    System.out.println(commonPool.getParallelism());
}
Also used : ForkJoinPool(java.util.concurrent.ForkJoinPool)

Aggregations

ForkJoinPool (java.util.concurrent.ForkJoinPool)24 Test (org.junit.Test)6 List (java.util.List)5 Map (java.util.Map)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Collectors (java.util.stream.Collectors)4 File (java.io.File)3 Serializable (java.io.Serializable)3 Arrays (java.util.Arrays)3 Collections (java.util.Collections)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 BuildTarget (com.facebook.buck.model.BuildTarget)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 HashSet (java.util.HashSet)2 ExecutionException (java.util.concurrent.ExecutionException)2 ExecutorService (java.util.concurrent.ExecutorService)2 ForkJoinWorkerThreadFactory (java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory)2 ForkJoinWorkerThread (java.util.concurrent.ForkJoinWorkerThread)2