java.util.concurrent.ForkJoinPool.commonPool()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.0k)|赞(0)|评价(0)|浏览(177)

本文整理了Java中java.util.concurrent.ForkJoinPool.commonPool()方法的一些代码示例,展示了ForkJoinPool.commonPool()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ForkJoinPool.commonPool()方法的具体详情如下:
包路径:java.util.concurrent.ForkJoinPool
类名称:ForkJoinPool
方法名:commonPool

ForkJoinPool.commonPool介绍

[英]Common (static) pool. Non-null for public use unless a static construction exception, but internal usages null-check on use to paranoically avoid potential initialization circularities as well as to simplify generated code.
[中]公共(静态)池。非null用于公共用途,除非静态构造异常,但内部使用null-check-on-use来偏执地避免潜在的初始化循环,并简化生成的代码。

代码示例

代码示例来源:origin: apache/incubator-druid

@Override
 public Executor createExecutor()
 {
  return ForkJoinPool.commonPool();
 }
},

代码示例来源:origin: jersey/jersey

/**
 * Creates a new JerseyPublisher using the {@link ForkJoinPool#commonPool()} for async delivery to subscribers
 * (unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
 * each task), with maximum buffer capacity of {@value DEFAULT_BUFFER_CAPACITY} and default {@link PublisherStrategy},
 * which is {@link PublisherStrategy#BEST_EFFORT}.
 */
public JerseyPublisher() {
  this(ForkJoinPool.commonPool(), DEFAULT_BUFFER_CAPACITY, PublisherStrategy.BEST_EFFORT);
}

代码示例来源:origin: jersey/jersey

/**
 * Creates a new JerseyPublisher using the {@link ForkJoinPool#commonPool()} for async delivery to subscribers
 * (unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
 * each task), with maximum buffer capacity of {@value DEFAULT_BUFFER_CAPACITY} and given {@link PublisherStrategy}.
 *
 * @param strategy publisher delivering strategy
 */
public JerseyPublisher(final PublisherStrategy strategy) {
  this(ForkJoinPool.commonPool(), DEFAULT_BUFFER_CAPACITY, strategy);
}

代码示例来源:origin: jersey/jersey

/**
 * Creates a new JerseyPublisher using the {@link ForkJoinPool#commonPool()} for async delivery to subscribers
 * (unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
 * each task), with maximum buffer capacity of {@value DEFAULT_BUFFER_CAPACITY} and given {@link PublisherStrategy}.
 *
 * @param strategy publisher delivering strategy
 */
public JerseyPublisher(final PublisherStrategy strategy) {
  this(ForkJoinPool.commonPool(), DEFAULT_BUFFER_CAPACITY, strategy);
}

代码示例来源:origin: jersey/jersey

/**
 * Creates a new JerseyPublisher using the {@link ForkJoinPool#commonPool()} for async delivery to subscribers
 * (unless it does not support a parallelism level of at least two, in which case, a new Thread is created to run
 * each task), with maximum buffer capacity of {@value DEFAULT_BUFFER_CAPACITY} and default {@link PublisherStrategy},
 * which is {@link PublisherStrategy#BEST_EFFORT}.
 */
public JerseyPublisher() {
  this(ForkJoinPool.commonPool(), DEFAULT_BUFFER_CAPACITY, PublisherStrategy.BEST_EFFORT);
}

代码示例来源:origin: spring-projects/spring-framework

@Override
public void afterPropertiesSet() {
  this.forkJoinPool = (this.commonPool ? ForkJoinPool.commonPool() :
      new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode));
}

代码示例来源:origin: org.springframework/spring-context

@Override
public void afterPropertiesSet() {
  this.forkJoinPool = (this.commonPool ? ForkJoinPool.commonPool() :
      new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode));
}

代码示例来源:origin: ben-manes/caffeine

@NonNull
Executor getExecutor() {
 return (executor == null) ? ForkJoinPool.commonPool() : executor;
}

代码示例来源:origin: ben-manes/caffeine

/**
 * Performs the maintenance work, blocking until the lock is acquired. Any exception thrown, such
 * as by {@link CacheWriter#delete}, is propagated to the caller.
 *
 * @param task an additional pending task to run, or {@code null} if not present
 */
void performCleanUp(@Nullable Runnable task) {
 evictionLock.lock();
 try {
  maintenance(task);
 } finally {
  evictionLock.unlock();
 }
 if ((drainStatus() == REQUIRED) && (executor == ForkJoinPool.commonPool())) {
  scheduleDrainBuffers();
 }
}

代码示例来源:origin: apache/hbase

@Override
protected AbstractFSWAL<?> createWAL() throws IOException {
 // just like what may do in the WALListeners, schedule an asynchronous task to call the
 // getWALs method.
 GET_WALS_FUTURE = ForkJoinPool.commonPool().submit(this::getWALs);
 // sleep a while to make the getWALs arrive before we return
 Threads.sleep(2000);
 return Mockito.mock(AbstractFSWAL.class);
}

代码示例来源:origin: apache/hbase

@Override
 protected ResultScanner getScanner(Scan scan) throws Exception {
  return CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).getScanner(scan);
 }
}

代码示例来源:origin: apache/hbase

@BeforeClass
public static void setUp() throws Exception {
 TEST_UTIL.startMiniCluster(1);
 TEST_UTIL.createTable(TABLE_NAME, FAMILY);
 CONN = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get();
 TABLE = CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool());
 TABLE.putAll(IntStream.range(0, 100).mapToObj(
  i -> new Put(Bytes.toBytes(String.format("%02d", i))).addColumn(FAMILY, CQ, Bytes.toBytes(i)))
   .collect(Collectors.toList())).get();
}

代码示例来源:origin: neo4j/neo4j

@Test
public void initShouldCreateThreadPool() throws Throwable
{
  ExecutorFactory mockExecutorFactory = mock( ExecutorFactory.class );
  when( mockExecutorFactory.create( anyInt(), anyInt(), any(), anyInt(), anyBoolean(), any() ) ).thenReturn( Executors.newCachedThreadPool() );
  ExecutorBoltScheduler scheduler =
      new ExecutorBoltScheduler( CONNECTOR_KEY, mockExecutorFactory, jobScheduler, logService, 0, 10, Duration.ofMinutes( 1 ), 0,
          ForkJoinPool.commonPool() );
  scheduler.start();
  verify( jobScheduler ).threadFactory( Group.BOLT_WORKER );
  verify( mockExecutorFactory, times( 1 ) ).create( anyInt(), anyInt(), any( Duration.class ), anyInt(), anyBoolean(), any( ThreadFactory.class ) );
}

代码示例来源:origin: neo4j/neo4j

@Test
public void shutdownShouldTerminateThreadPool() throws Throwable
{
  ExecutorService cachedThreadPool = Executors.newCachedThreadPool();
  ExecutorFactory mockExecutorFactory = mock( ExecutorFactory.class );
  when( mockExecutorFactory.create( anyInt(), anyInt(), any(), anyInt(), anyBoolean(), any() ) ).thenReturn( cachedThreadPool );
  ExecutorBoltScheduler scheduler =
      new ExecutorBoltScheduler( CONNECTOR_KEY, mockExecutorFactory, jobScheduler, logService, 0, 10, Duration.ofMinutes( 1 ), 0,
          ForkJoinPool.commonPool() );
  scheduler.start();
  scheduler.stop();
  assertTrue( cachedThreadPool.isShutdown() );
}

代码示例来源:origin: apache/hbase

private static Pair<List<Result>, ScanMetrics> doScanWithAsyncTableScanner(Scan scan)
  throws IOException {
 try (ResultScanner scanner =
   CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).getScanner(scan)) {
  List<Result> results = new ArrayList<>();
  for (Result result; (result = scanner.next()) != null;) {
   results.add(result);
  }
  return Pair.newPair(results, scanner.getScanMetrics());
 }
}

代码示例来源:origin: graphql-java/graphql-java

public ReactiveStreamsMessagePublisher(final int count) {
  Iterable<Message> iterable = mkIterable(count, at -> {
    Message message = new Message("sender" + at, "text" + at);
    return examineMessage(message, at);
  });
  iterablePublisher = new AsyncIterablePublisher<>(iterable, ForkJoinPool.commonPool());
}

代码示例来源:origin: reactor/reactor-core

@Test
public void classicJust() {
  AssertSubscriber<Integer> ts = AssertSubscriber.create();
  Mono.just(1)
    .subscribeOn(Schedulers.fromExecutorService(ForkJoinPool.commonPool()))
    .subscribe(ts);
  ts.await(Duration.ofSeconds(5));
  ts.assertValues(1)
   .assertNoError()
   .assertComplete();
}

代码示例来源:origin: apache/hbase

@Override
protected List<Result> doScan(Scan scan) throws Exception {
 AsyncTable<ScanResultConsumer> table =
  ASYNC_CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool());
 SimpleScanResultConsumer consumer = new SimpleScanResultConsumer();
 table.scan(scan, consumer);
 List<Result> results = consumer.getAll();
 if (scan.getBatch() > 0) {
  results = convertFromBatchResult(results);
 }
 return results;
}

代码示例来源:origin: apache/hbase

private static Pair<List<Result>, ScanMetrics> doScanWithAsyncTableScan(Scan scan)
  throws Exception {
 SimpleScanResultConsumer consumer = new SimpleScanResultConsumer();
 CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).scan(scan, consumer);
 return Pair.newPair(consumer.getAll(), consumer.getScanMetrics());
}

代码示例来源:origin: reactor/reactor-core

@Test
public void classicEmpty() {
  AssertSubscriber<Integer> ts = AssertSubscriber.create();
  Flux.<Integer>empty().subscribeOn(Schedulers.fromExecutorService(ForkJoinPool.commonPool())).subscribe(ts);
  ts.await(Duration.ofSeconds(5));
  ts.assertNoValues()
  .assertNoError()
  .assertComplete();
}

相关文章

微信公众号

最新文章

更多

ForkJoinPool类方法