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

The following examples show how to use java.util.concurrent.ForkJoinTask#inForkJoinPool() . 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: ArrayDoubler.java    From openjdk-systemtest with Apache License 2.0 6 votes vote down vote up
protected void compute() 
{
	if(endValue - startValue > MAX_ELEMENTS_TO_PROCESS)			// If there are too many elements to process in one operation...
	{
		if(ForkJoinTask.inForkJoinPool())						// ... and if we are in a ForkJoinPool ...
		{
			int halfWay = (endValue + startValue) / 2;
			invokeAll(new ArrayDoubler(array, startValue, halfWay), new ArrayDoubler(array, halfWay, endValue));
			return;
		}
	}
	
	for(int i = startValue; i < endValue; i++)					// If we aren't in a ForkJoinPool or if there are not a large number of elements to be processed
	{
		array[i] = array[i] * 2;
	}
}
 
Example 2
Source File: FibonacciFJ.java    From JPPF with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
  FibonacciResult result;
  if(ForkJoinTask.inForkJoinPool()) result = new FibonacciResult(true, new FibonacciTaskFJ(n).compute());
  else result = new FibonacciResult(false, fib(n));
  setResult(result);
}
 
Example 3
Source File: ForkJoinQuiescingExecutor.java    From bazel with Apache License 2.0 5 votes vote down vote up
@Override
protected void executeRunnable(WrappedRunnable runnable) {
  if (ForkJoinTask.inForkJoinPool()) {
    @SuppressWarnings("unused") 
    Future<?> possiblyIgnoredError = ForkJoinTask.adapt(runnable).fork();
  } else {
    super.executeRunnable(runnable);
  }
}
 
Example 4
Source File: WakeSharedPool.java    From reef with Apache License 2.0 5 votes vote down vote up
public void submit(final ForkJoinTask<?> t) {
  if (ForkJoinTask.inForkJoinPool()) {
    ForkJoinTask.invokeAll(t);
    // alternatively just pool().pool.execute(t), which simply forces it to be this pool
    // (right now we expect only one anyway)
  } else {
    pool.submit(t);
  }
}
 
Example 5
Source File: BufferParallelAggregation.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
private static int availableParallelism() {
  return ForkJoinTask.inForkJoinPool()
          ? ForkJoinTask.getPool().getParallelism()
          : ForkJoinPool.getCommonPoolParallelism();
}
 
Example 6
Source File: ParallelAggregation.java    From RoaringBitmap with Apache License 2.0 4 votes vote down vote up
private static int availableParallelism() {
  return ForkJoinTask.inForkJoinPool()
          ? ForkJoinTask.getPool().getParallelism()
          : ForkJoinPool.getCommonPoolParallelism();
}
 
Example 7
Source File: MiGzInputStream.java    From migz with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Creates a new MiGzInputStream that will read MiGz-compressed bytes from the specified underlying
 * inputStream using the default number of threads.  Worker tasks will execute on the current {@link ForkJoinPool}
 * returned by {@link ForkJoinTask#getPool()} if applicable, the {@link ForkJoinPool#commonPool()} otherwise,
 * with a maximum number of concurrent workers equal to the target parallelism of the pool.
 *
 * @param inputStream the stream from which compressed bytes will be read
 * @throws UncheckedIOException if a problem occurs reading the block size header
 */
public MiGzInputStream(InputStream inputStream) {
  this(inputStream, ForkJoinTask.inForkJoinPool() ?  ForkJoinTask.getPool() : ForkJoinPool.commonPool());
}
 
Example 8
Source File: MiGzOutputStream.java    From migz with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Creates a new MiGzOutputStream that will output MiGz-compressed bytes to the specified underlying
 * outputStream using the default block size.  Worker tasks will execute on the current {@link ForkJoinPool} returned
 * by {@link ForkJoinTask#getPool()} if applicable, or the {@link ForkJoinPool#commonPool()} otherwise.
 *
 * @param outputStream the stream to which compressed bytes will be written
 */
public MiGzOutputStream(OutputStream outputStream) {
  this(outputStream, ForkJoinTask.inForkJoinPool() ? ForkJoinTask.getPool() : ForkJoinPool.commonPool(),
      DEFAULT_BLOCK_SIZE);
}