java.util.concurrent.ForkJoinTask#inForkJoinPool ( )源码实例Demo

下面列出了java.util.concurrent.ForkJoinTask#inForkJoinPool ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-systemtest   文件: ArrayDoubler.java
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;
	}
}
 
源代码2 项目: JPPF   文件: FibonacciFJ.java
@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);
}
 
源代码3 项目: bazel   文件: ForkJoinQuiescingExecutor.java
@Override
protected void executeRunnable(WrappedRunnable runnable) {
  if (ForkJoinTask.inForkJoinPool()) {
    @SuppressWarnings("unused") 
    Future<?> possiblyIgnoredError = ForkJoinTask.adapt(runnable).fork();
  } else {
    super.executeRunnable(runnable);
  }
}
 
源代码4 项目: reef   文件: WakeSharedPool.java
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);
  }
}
 
源代码5 项目: RoaringBitmap   文件: BufferParallelAggregation.java
private static int availableParallelism() {
  return ForkJoinTask.inForkJoinPool()
          ? ForkJoinTask.getPool().getParallelism()
          : ForkJoinPool.getCommonPoolParallelism();
}
 
源代码6 项目: RoaringBitmap   文件: ParallelAggregation.java
private static int availableParallelism() {
  return ForkJoinTask.inForkJoinPool()
          ? ForkJoinTask.getPool().getParallelism()
          : ForkJoinPool.getCommonPoolParallelism();
}
 
源代码7 项目: migz   文件: MiGzInputStream.java
/**
 * 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());
}
 
源代码8 项目: migz   文件: MiGzOutputStream.java
/**
 * 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);
}