• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ForkJoinWorkerThreadFactory类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: forkJoin

import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; //导入依赖的package包/类
@Test
public void forkJoin() throws Exception {
  int n = Runtime.getRuntime().availableProcessors();
  Config conf = ConfigFactory.empty()
      .withValue("executors", ConfigValueFactory.fromAnyRef("forkjoin, asyncMode"));
  new MockUnit(Env.class, Binder.class)
      .expect(executors)
      .expect(unit -> {
        ForkJoinPool pool = unit.constructor(ForkJoinPool.class)
            .args(int.class, ForkJoinWorkerThreadFactory.class, UncaughtExceptionHandler.class,
                boolean.class)
            .build(eq(n), isA(ForkJoinWorkerThreadFactory.class), eq(null), eq(false));
        unit.registerMock(ExecutorService.class, pool);
      })
      .expect(bind("default", true, ExecutorService.class, Executor.class, ForkJoinPool.class))
      .expect(onStop)
      .run(unit -> {
        new Exec().configure(unit.get(Env.class), conf, unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:21,代码来源:ExecTest.java


示例2: forkJoinAlternative

import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; //导入依赖的package包/类
@Test
public void forkJoinAlternative() throws Exception {
  int n = Runtime.getRuntime().availableProcessors();
  Config conf = ConfigFactory.empty()
      .withValue("executors.default.type", ConfigValueFactory.fromAnyRef("forkjoin"))
      .withValue("executors.default.asyncMode", ConfigValueFactory.fromAnyRef(false));
  new MockUnit(Env.class, Binder.class)
      .expect(executors)
      .expect(unit -> {
        ForkJoinPool pool = unit.constructor(ForkJoinPool.class)
            .args(int.class, ForkJoinWorkerThreadFactory.class, UncaughtExceptionHandler.class,
                boolean.class)
            .build(eq(n), isA(ForkJoinWorkerThreadFactory.class), eq(null), eq(false));
        unit.registerMock(ExecutorService.class, pool);
      })
      .expect(bind("default", true, ExecutorService.class, Executor.class, ForkJoinPool.class))
      .expect(onStop)
      .run(unit -> {
        new Exec().configure(unit.get(Env.class), conf, unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:22,代码来源:ExecTest.java


示例3: forkJoinAsync

import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; //导入依赖的package包/类
@Test
public void forkJoinAsync() throws Exception {
  int n = 1;
  Config conf = ConfigFactory.empty()
      .withValue("executors", ConfigValueFactory.fromAnyRef("forkjoin=1, asyncMode=true"));
  new MockUnit(Env.class, Binder.class)
      .expect(executors)
      .expect(unit -> {
        ForkJoinPool pool = unit.constructor(ForkJoinPool.class)
            .args(int.class, ForkJoinWorkerThreadFactory.class, UncaughtExceptionHandler.class,
                boolean.class)
            .build(eq(n), isA(ForkJoinWorkerThreadFactory.class), eq(null), eq(true));
        unit.registerMock(ExecutorService.class, pool);
      })
      .expect(bind("default", true, ExecutorService.class, Executor.class, ForkJoinPool.class))
      .expect(onStop)
      .run(unit -> {
        new Exec().configure(unit.get(Env.class), conf, unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:21,代码来源:ExecTest.java


示例4: forkJoinAsyncAlternative

import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; //导入依赖的package包/类
@Test
public void forkJoinAsyncAlternative() throws Exception {
  int n = 1;
  Config conf = ConfigFactory.empty()
      .withValue("executors.default.type", ConfigValueFactory.fromAnyRef("forkjoin"))
      .withValue("executors.default.size", ConfigValueFactory.fromAnyRef(1))
      .withValue("executors.default.asyncMode", ConfigValueFactory.fromAnyRef(true));
  new MockUnit(Env.class, Binder.class)
      .expect(executors)
      .expect(unit -> {
        ForkJoinPool pool = unit.constructor(ForkJoinPool.class)
            .args(int.class, ForkJoinWorkerThreadFactory.class, UncaughtExceptionHandler.class,
                boolean.class)
            .build(eq(n), isA(ForkJoinWorkerThreadFactory.class), eq(null), eq(true));
        unit.registerMock(ExecutorService.class, pool);
      })
      .expect(bind("default", true, ExecutorService.class, Executor.class, ForkJoinPool.class))
      .expect(onStop)
      .run(unit -> {
        new Exec().configure(unit.get(Env.class), conf, unit.get(Binder.class));
      });
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:23,代码来源:ExecTest.java


示例5: getExecutor

import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; //导入依赖的package包/类
ExecutorService getExecutor(int asyncThreads) {
  // TODO(carl-mastrangelo): This should not be necessary.  I don't know where this should be
  // put.  Move it somewhere else, or remove it if no longer necessary.
  // See: https://github.com/grpc/grpc-java/issues/2119
  return new ForkJoinPool(asyncThreads,
      new ForkJoinWorkerThreadFactory() {
        final AtomicInteger num = new AtomicInteger();
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
          ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool);
          thread.setDaemon(true);
          thread.setName("server-worker-" + "-" + num.getAndIncrement());
          return thread;
        }
      }, UncaughtExceptionHandlers.systemExit(), true /* async */);
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:17,代码来源:LoadServer.java


示例6: getExecutor

import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; //导入依赖的package包/类
private static synchronized ExecutorService getExecutor() {
  if (clientExecutor == null) {
    clientExecutor = new ForkJoinPool(
        Runtime.getRuntime().availableProcessors(),
        new ForkJoinWorkerThreadFactory() {
          final AtomicInteger num = new AtomicInteger();
          @Override
          public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
            ForkJoinWorkerThread thread = defaultForkJoinWorkerThreadFactory.newThread(pool);
            thread.setDaemon(true);
            thread.setName("grpc-client-app-" + "-" + num.getAndIncrement());
            return thread;
          }
        }, UncaughtExceptionHandlers.systemExit(), true /* async */);
  }
  return clientExecutor;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:18,代码来源:Utils.java


示例7: fjwtf

import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; //导入依赖的package包/类
private static ForkJoinWorkerThreadFactory fjwtf(final String name) {
  AtomicLong id = new AtomicLong();
  return pool -> {
    ForkJoinWorkerThread thread = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
    thread.setName(name + "-" + id.incrementAndGet());
    return thread;
  };
}
 
开发者ID:jooby-project,项目名称:jooby,代码行数:9,代码来源:Exec.java


示例8: newForkJoinPoolTestSuiteWithParallelism

import java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory; //导入依赖的package包/类
public static TestSuite newForkJoinPoolTestSuiteWithParallelism(final int parallelism) throws Exception {
    ExecutorTestSuiteBuilder<ExecutorService> fjpSuite = ExecutorTestSuiteBuilder.using(new ExecutorTestSubjectGenerator<ExecutorService>() {
        @Override
        protected ExecutorService createExecutor(final ThreadFactory threadFactory) {
            ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {
                @Override
                public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
                    ForkJoinWorkerThread thread = new ForkJoinWorkerThread(pool) {
                        @Override
                        public void interrupt() {
                            notifyThreadInterrupted(this);
                            super.interrupt();
                        }
                    };
                    notifyNewThread(threadFactory, thread);
                    thread.setDaemon(true);
                    return thread;
                }
            };
            return new ForkJoinPool(parallelism, factory, null, false);
        }
    }).named("ForkJoinPool[parallelism=" + parallelism + "]")
        .withFeatures(EXECUTOR_SERVICE, IGNORES_INTERRUPTS)
        .withConcurrencyLevel(parallelism);

    /*
     * This test fails sporadically, possibly more consistently with parallelism=2 than 3. ForkJoinPool#invokeAll cancels tasks when it
     * sees an exception. Whether this cancellation makes it into the returned future depends on a race condition in (parallel)
     * execution of the tasks.
     *
     * It's not completely clear whether this complies with the spec. The spec doesn't explicitly state that the tasks run
     * independently, but it feels odd for behaviour of later tasks to depend on earlier ones that threw an exception. That said,
     * perhaps fork-join should expect this sort of coupling between tasks, in which case cancellation of subsequent tasks may be
     * reasonable.
     */
    fjpSuite.suppressing(InvokeAllTester.class.getMethod("testInvokeAllMixedCompletesAllTasks_NoTimeout"),
                         InvokeAllTester.class.getMethod("testInterruptedWhileWaiting_NoTimeout"),
                         InvokeAllTester.class.getMethod("testInterruptedWhileWaiting_Timeout"));

    return fjpSuite.createTestSuite();
}
 
开发者ID:joekearney,项目名称:guava-testlib-executors,代码行数:42,代码来源:TestsForExecutors.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TiUIView类代码示例发布时间:2022-05-21
下一篇:
Java EncodedDataBlock类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap