当前位置: 首页>>代码示例>>Java>>正文


Java ForkJoinPool.commonPool方法代码示例

本文整理汇总了Java中java.util.concurrent.ForkJoinPool.commonPool方法的典型用法代码示例。如果您正苦于以下问题:Java ForkJoinPool.commonPool方法的具体用法?Java ForkJoinPool.commonPool怎么用?Java ForkJoinPool.commonPool使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.concurrent.ForkJoinPool的用法示例。


在下文中一共展示了ForkJoinPool.commonPool方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCreateKeyMultithreaded

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
@Test
public void testCreateKeyMultithreaded() {
    final int count = 100000;

    final Collection<Callable<String>> tasks = IntStream.range(0, count).boxed()
        .map(i -> (Callable<String>) () -> KeyGenerator.createKey()).collect(Collectors.toList());

    final ForkJoinPool pool = ForkJoinPool.commonPool();

    final List<Future<String>> results = pool.invokeAll(tasks);

    final Set<String> keys = results.stream().map(t -> {
        try {
            return t.get();
        } catch (InterruptedException | ExecutionException e) {
            throw new IllegalStateException(e);
        }
    }).collect(Collectors.toSet());

    Assert.assertEquals("If " + count + " key generations are performed in parallel, it should yield " + count
        + " of distinct keys", count, keys.size());
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:23,代码来源:KeyGeneratorTest.java

示例2: dispatch

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
public static void dispatch(int trafficUnitsNumber, double timeSec, DateLocation dateLocation, double[] speedLimitByLane) {

        ExecutorService execService =  ForkJoinPool.commonPool();
        try (SubmissionPublisher<Integer> publisher = new SubmissionPublisher<>()){
            subscribe(publisher, execService, Process.AVERAGE_SPEED, timeSec, dateLocation, speedLimitByLane);
            subscribe(publisher, execService, Process.TRAFFIC_DENSITY, timeSec, dateLocation, speedLimitByLane);
            publisher.submit(trafficUnitsNumber);
        } finally {
            try {
                execService.shutdown();
                execService.awaitTermination(1, TimeUnit.SECONDS);
            } catch (Exception ex) {
                System.out.println("Caught around execService.awaitTermination(): " + ex.getClass().getName());
            } finally {
                execService.shutdownNow();
            }
        }
    }
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:19,代码来源:Dispatcher.java

示例3: demo4_Flow_submissionPublisher

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
private static void demo4_Flow_submissionPublisher() {
    System.out.println();

    ExecutorService execService =  ForkJoinPool.commonPool();//Executors.newFixedThreadPool(3);
    try (SubmissionPublisher<Integer> publisher = new SubmissionPublisher<>()){//execService, 1)){
        demoSubscribe(publisher, execService, "One");
        demoSubscribe(publisher, execService, "Two");
        demoSubscribe(publisher, execService, "Three");
        IntStream.range(1, 5).forEach(publisher::submit);
    } finally {
        try {
            execService.shutdown();
            int shutdownDelaySec = 1;
            System.out.println("Waiting for " + shutdownDelaySec + " sec before shutting down service...");
            execService.awaitTermination(shutdownDelaySec, TimeUnit.SECONDS);
        } catch (Exception ex) {
            System.out.println("Caught around execService.awaitTermination(): " + ex.getClass().getName());
        } finally {
            System.out.println("Calling execService.shutdownNow()...");
            List<Runnable> l = execService.shutdownNow();
            System.out.println(l.size() + " tasks were waiting to be executed. Service stopped.");
        }

    }

}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:27,代码来源:Chapter07Concurrency04.java

示例4: Flow_customsubmissionPublisher

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
private static void Flow_customsubmissionPublisher() {
    ExecutorService execService =  ForkJoinPool.commonPool();//Executors.newFixedThreadPool(3);
    try (DockerXDemoPublisher<Integer> publisher = new  DockerXDemoPublisher<>(execService)){
        demoSubscribe(publisher,  "One");
        demoSubscribe(publisher,  "Two");
        demoSubscribe(publisher,  "Three");
        IntStream.range(1, 5).forEach(publisher::submit);
    } finally {
        try {
            execService.shutdown();
            int shutdownDelaySec = 1;
            System.out.println("………………等待 " + shutdownDelaySec + " 秒后结束服务……………… ");
            execService.awaitTermination(shutdownDelaySec, TimeUnit.SECONDS);
        } catch (Exception ex) {
            System.out.println("捕获到 execService.awaitTermination()方法的异常: " + ex.getClass().getName());
        } finally {
            System.out.println("调用 execService.shutdownNow()结束服务...");
            List<Runnable> l = execService.shutdownNow();
            System.out.println("还剩 "+l.size() + " 个任务等待被执行,服务已关闭 ");
        }

    }
}
 
开发者ID:kkTranslation,项目名称:Java-9-Spring-Webflux,代码行数:24,代码来源:DockerXDemoApplication.java

示例5: onCompletedImpl

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
private void onCompletedImpl(@NotNull Runnable continuation, boolean useExecutionContext) {
	Executor executor;
	if (continueOnCapturedContext) {
		SynchronizationContext synchronizationContext = SynchronizationContext.getCurrent();
		if (synchronizationContext != null && synchronizationContext.getClass() != SynchronizationContext.class) {
			executor = synchronizationContext;
		} else {
			executor = ForkJoinPool.commonPool();
		}
	} else {
		executor = ForkJoinPool.commonPool();
	}

	Runnable wrappedContinuation = useExecutionContext ? ExecutionContext.wrap(continuation) : continuation;
	future.whenCompleteAsync((result, exception) -> wrappedContinuation.run(), executor);
}
 
开发者ID:tunnelvisionlabs,项目名称:java-threading,代码行数:17,代码来源:FutureAwaitable.java

示例6: demo2_ForkJoin_execute_join

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
private static void demo2_ForkJoin_execute_join() {
    System.out.println();

    AverageSpeed averageSpeed = createTask();

    ForkJoinPool commonPool = ForkJoinPool.commonPool();
    commonPool.execute(averageSpeed);
    double result = averageSpeed.join();

    System.out.println("result = " + result);
}
 
开发者ID:PacktPublishing,项目名称:Java-9-Cookbook,代码行数:12,代码来源:Chapter07Concurrency04.java

示例7: init

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
@Setup
public void init() throws Exception {
    repoDir = Files.createTempDirectory("jmh-gitrepository.").toFile();
    repo = new GitRepository(mock(Project.class), repoDir, format, ForkJoinPool.commonPool(),
                             System.currentTimeMillis(), AUTHOR);
    currentRevision = 1;

    for (int i = 0; i < previousCommits; i++) {
        addCommit();
    }
}
 
开发者ID:line,项目名称:centraldogma,代码行数:12,代码来源:GitRepositoryBenchmark.java

示例8: screenExecutor

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
 * Null-checks user executor argument, and translates uses of
 * commonPool to asyncPool in case parallelism disabled.
 */
static Executor screenExecutor(Executor e) {
    if (!useCommonPool && e == ForkJoinPool.commonPool())
        return asyncPool;
    if (e == null) throw new NullPointerException();
    return e;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:11,代码来源:CompletableFuture.java

示例9: testConstructor1

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
 * A default-constructed SubmissionPublisher has no subscribers,
 * is not closed, has default buffer size, and uses the
 * defaultExecutor
 */
public void testConstructor1() {
    SubmissionPublisher<Integer> p = new SubmissionPublisher<>();
    checkInitialState(p);
    assertEquals(p.getMaxBufferCapacity(), Flow.defaultBufferSize());
    Executor e = p.getExecutor(), c = ForkJoinPool.commonPool();
    if (ForkJoinPool.getCommonPoolParallelism() > 1)
        assertSame(e, c);
    else
        assertNotSame(e, c);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:SubmissionPublisherTest.java

示例10: testDefaultExecutor

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
/**
 * defaultExecutor by default returns the commonPool if
 * it supports more than one thread.
 */
public void testDefaultExecutor() {
    CompletableFuture<Integer> f = new CompletableFuture<>();
    Executor e = f.defaultExecutor();
    Executor c = ForkJoinPool.commonPool();
    if (ForkJoinPool.getCommonPoolParallelism() > 1)
        assertSame(e, c);
    else
        assertNotSame(e, c);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:14,代码来源:CompletableFutureTest.java

示例11: LocalComputationManager

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
public LocalComputationManager(LocalComputationConfig config) throws IOException {
    this(config, ForkJoinPool.commonPool());
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:4,代码来源:LocalComputationManager.java

示例12: beforeClass

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
@BeforeClass
public static void beforeClass() throws Exception {
    pm = new DefaultProjectManager(rootDir.getRoot(), ForkJoinPool.commonPool(), null);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:5,代码来源:PluginTest.java

示例13: newRepositoryManager

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
private GitRepositoryManager newRepositoryManager() {
    return new GitRepositoryManager(mock(Project.class), rootDir(), ForkJoinPool.commonPool());
}
 
开发者ID:line,项目名称:centraldogma,代码行数:4,代码来源:GitRepositoryManagerTest.java

示例14: init

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
@Before
public void init() throws IOException {
    m = new RepositoryManagerWrapper(new GitRepositoryManager(mock(Project.class), rootDir.getRoot(),
                                                              ForkJoinPool.commonPool()),
                                     RepositoryWrapper::new);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:7,代码来源:RepositoryManagerWrapperTest.java

示例15: init

import java.util.concurrent.ForkJoinPool; //导入方法依赖的package包/类
@BeforeClass
public static void init() throws Exception {
    pm = new DefaultProjectManager(rootDir.getRoot(), ForkJoinPool.commonPool(), null);
}
 
开发者ID:line,项目名称:centraldogma,代码行数:5,代码来源:DefaultMetaRepositoryTest.java


注:本文中的java.util.concurrent.ForkJoinPool.commonPool方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。