@Override public Executor createExecutor() { return ForkJoinPool.commonPool(); } },
/** * 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); }
/** * 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); }
/** * 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); }
/** * 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); }
@Override public void afterPropertiesSet() { this.forkJoinPool = (this.commonPool ? ForkJoinPool.commonPool() : new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode)); }
@Override public void afterPropertiesSet() { this.forkJoinPool = (this.commonPool ? ForkJoinPool.commonPool() : new ForkJoinPool(this.parallelism, this.threadFactory, this.uncaughtExceptionHandler, this.asyncMode)); }
@NonNull Executor getExecutor() { return (executor == null) ? ForkJoinPool.commonPool() : executor; }
/** * 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(); } }
@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); }
@Override protected ResultScanner getScanner(Scan scan) throws Exception { return CONN.getTable(TABLE_NAME, ForkJoinPool.commonPool()).getScanner(scan); } }
@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(); }
@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 ) ); }
@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() ); }
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()); } }
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()); }
@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(); }
@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; }
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()); }
@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(); }