Java Code Examples for java.util.concurrent.ForkJoinTask#join()

The following examples show how to use java.util.concurrent.ForkJoinTask#join() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InMemCubeBuilder2.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Build all the cuboids and wait for all the tasks finished. 
 * 
 * @param input
 * @param listener
 * @return
 * @throws IOException
 */
private <T> NavigableMap<Long, CuboidResult> buildAndCollect(final RecordConsumeBlockingQueueController<T> input,
        final ICuboidResultListener listener) throws IOException {

    long startTime = System.currentTimeMillis();
    logger.info("In Mem Cube Build2 start, {}", cubeDesc.getName());

    // build base cuboid
    buildBaseCuboid(input, listener);

    ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
            final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
            worker.setName("inmem-cubing-cuboid-worker-" + worker.getPoolIndex());
            return worker;
        }
    };
    ForkJoinPool builderPool = new ForkJoinPool(taskThreadCount, factory, null, true);
    ForkJoinTask rootTask = builderPool.submit(new Runnable() {
        @Override
        public void run() {
            startBuildFromBaseCuboid();
        }
    });
    rootTask.join();

    long endTime = System.currentTimeMillis();
    logger.info("In Mem Cube Build2 end, {}, takes {} ms", cubeDesc.getName(), (endTime - startTime));
    logger.info("total CuboidResult count: {}", resultCollector.getAllResult().size());
    return resultCollector.getAllResult();
}
 
Example 2
Source File: ObjectPoolTest.java    From concurrentli with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void test() {
  ForkJoinPool threadPool = ForkJoinPool.commonPool();
  ObjectPool<String> pool = new ObjectPool<>(0, 2, () -> "abc");

  ObjectPool<java.lang.String>.Entry entry1 = pool.tryGet();
  ObjectPool<java.lang.String>.Entry entry2 = pool.tryGet();

  Assert.assertNotNull(entry1);
  Assert.assertNotNull(entry2);

  ForkJoinTask<?> task1 = threadPool.submit(() -> {
    Assert.assertEquals("abc", entry1.get());
    entry1.close();
  });

  ForkJoinTask<?> task2 = threadPool.submit(() -> {
    entry2.close("def");
  });

  // note that these joins create a memory barrier, so the pool will certainly have the returned items as seen by
  // this main thread
  task1.join();
  task2.join();

  ObjectPool<java.lang.String>.Entry entry3 = pool.tryGet();
  ObjectPool<java.lang.String>.Entry entry4 = pool.tryGet();

  Assert.assertNotNull(entry3);
  Assert.assertNotNull(entry4);

  Assert.assertTrue(entry3.get().equals("def") || entry4.get().equals("def"));
  Assert.assertEquals(2, pool.getItemCreationCount());

  Assert.assertNull(pool.tryGet());
  Assert.assertEquals("abc", pool.get().get());
}
 
Example 3
Source File: SimulationCore.java    From Shuffle-Move with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return
 */
public Collection<SimulationResult> computeWithoutMove() {
   Collection<SimulationFeeder> feeders = SimulationFeeder.getFeedersFor(0, getStage(), possibleBlocks,
         preferredCount);
   Collection<SimulationTask> toRun = new SimulationCreationTask(this, null, feeders).invoke();
   ForkJoinTask<SimulationResult> assembler = new SimulationResultsAssembler(null, processUUID, toRun, startTime)
         .fork();
   SimulationResult settleResult = assembler.join();
   if (settleResult.getBoard().equals(board)) {
      return null;
   } else {
      return Arrays.asList(settleResult);
   }
}
 
Example 4
Source File: InMemCubeBuilder2.java    From kylin with Apache License 2.0 5 votes vote down vote up
/**
 * Build all the cuboids and wait for all the tasks finished. 
 * 
 * @param input
 * @param listener
 * @return
 * @throws IOException
 */
private <T> NavigableMap<Long, CuboidResult> buildAndCollect(final RecordConsumeBlockingQueueController<T> input,
        final ICuboidResultListener listener) throws IOException {

    long startTime = System.currentTimeMillis();
    logger.info("In Mem Cube Build2 start, {}", cubeDesc.getName());

    // build base cuboid
    buildBaseCuboid(input, listener);

    ForkJoinWorkerThreadFactory factory = new ForkJoinWorkerThreadFactory() {
        @Override
        public ForkJoinWorkerThread newThread(ForkJoinPool pool) {
            final ForkJoinWorkerThread worker = ForkJoinPool.defaultForkJoinWorkerThreadFactory.newThread(pool);
            worker.setName("inmem-cubing-cuboid-worker-" + worker.getPoolIndex());
            return worker;
        }
    };
    ForkJoinPool builderPool = new ForkJoinPool(taskThreadCount, factory, null, true);
    ForkJoinTask rootTask = builderPool.submit(new Runnable() {
        @Override
        public void run() {
            startBuildFromBaseCuboid();
        }
    });
    rootTask.join();

    long endTime = System.currentTimeMillis();
    logger.info("In Mem Cube Build2 end, {}, takes {} ms", cubeDesc.getName(), (endTime - startTime));
    logger.info("total CuboidResult count: {}", resultCollector.getAllResult().size());
    return resultCollector.getAllResult();
}
 
Example 5
Source File: MergeSort.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 6
Source File: MergeSort.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 7
Source File: MergeSort.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 8
Source File: MergeSort.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 9
Source File: MergeSort.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 10
Source File: MergeSort.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 11
Source File: MergeSort.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 12
Source File: MergeSort.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 13
Source File: MergeSort.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 14
Source File: MergeSort.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 15
Source File: MergeSort.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}
 
Example 16
Source File: MergeSort.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Sorts all the elements of the given array using the ForkJoin framework
 * @param array the array to sort
 */
public void sort(int[] array) {
    ForkJoinTask<Void> job = pool.submit(new MergeSortTask(array, 0, array.length));
    job.join();
}