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


Java ForkJoinWorkerThreadFactory类代码示例

本文整理汇总了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;未经允许,请勿转载。