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

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

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

ForkJoinPool.addSubmission介绍

[英]Enqueues the given task in the submissionQueue. Same idea as ForkJoinWorkerThread.pushTask except for use of submissionLock.
[中]将给定任务排入submissionQueue。与ForkJoinWorkerThread的想法相同。pushTask(使用submissionLock除外)。

代码示例

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Unless terminating, forks task if within an ongoing FJ
 * computation in the current pool, else submits as external task.
 */
private <T> void forkOrSubmit(ForkJoinTask<T> task) {
  ForkJoinWorkerThread w;
  Thread t = Thread.currentThread();
  if (shutdown)
    throw new RejectedExecutionException();
  if ((t instanceof ForkJoinWorkerThread) &&
    (w = (ForkJoinWorkerThread)t).pool == this)
    w.pushTask(task);
  else
    addSubmission(task);
}

代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166

/**
 * Unless terminating, forks task if within an ongoing FJ
 * computation in the current pool, else submits as external task.
 */
private <T> void forkOrSubmit(ForkJoinTask<T> task) {
  ForkJoinWorkerThread w;
  Thread t = Thread.currentThread();
  if (shutdown)
    throw new RejectedExecutionException();
  if ((t instanceof ForkJoinWorkerThread) &&
    (w = (ForkJoinWorkerThread)t).pool == this)
    w.pushTask(task);
  else
    addSubmission(task);
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Unless terminating, forks task if within an ongoing FJ
 * computation in the current pool, else submits as external task.
 */
private <T> void forkOrSubmit(ForkJoinTask<T> task) {
  ForkJoinWorkerThread w;
  Thread t = Thread.currentThread();
  if (shutdown)
    throw new RejectedExecutionException();
  if ((t instanceof ForkJoinWorkerThread) &&
    (w = (ForkJoinWorkerThread)t).pool == this)
    w.pushTask(task);
  else
    addSubmission(task);
}

代码示例来源:origin: org.apidesign.bck2brwsr/emul

/**
 * Performs the given task, returning its result upon completion.
 * If the computation encounters an unchecked Exception or Error,
 * it is rethrown as the outcome of this invocation.  Rethrown
 * exceptions behave in the same way as regular exceptions, but,
 * when possible, contain stack traces (as displayed for example
 * using {@code ex.printStackTrace()}) of both the current thread
 * as well as the thread actually encountering the exception;
 * minimally only the latter.
 *
 * @param task the task
 * @return the task's result
 * @throws NullPointerException if the task is null
 * @throws RejectedExecutionException if the task cannot be
 *         scheduled for execution
 */
public <T> T invoke(ForkJoinTask<T> task) {
  Thread t = Thread.currentThread();
  if (task == null)
    throw new NullPointerException();
  if (shutdown)
    throw new RejectedExecutionException();
  if ((t instanceof ForkJoinWorkerThread) &&
    ((ForkJoinWorkerThread)t).pool == this)
    return task.invoke();  // bypass submit if in same pool
  else {
    addSubmission(task);
    return task.join();
  }
}

代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166

/**
 * Performs the given task, returning its result upon completion.
 * If the computation encounters an unchecked Exception or Error,
 * it is rethrown as the outcome of this invocation.  Rethrown
 * exceptions behave in the same way as regular exceptions, but,
 * when possible, contain stack traces (as displayed for example
 * using {@code ex.printStackTrace()}) of both the current thread
 * as well as the thread actually encountering the exception;
 * minimally only the latter.
 *
 * @param task the task
 * @return the task's result
 * @throws NullPointerException if the task is null
 * @throws RejectedExecutionException if the task cannot be
 *         scheduled for execution
 */
public <T> T invoke(ForkJoinTask<T> task) {
  Thread t = Thread.currentThread();
  if (task == null)
    throw new NullPointerException();
  if (shutdown)
    throw new RejectedExecutionException();
  if ((t instanceof ForkJoinWorkerThread) &&
    ((ForkJoinWorkerThread)t).pool == this)
    return task.invoke();  // bypass submit if in same pool
  else {
    addSubmission(task);
    return task.join();
  }
}

代码示例来源:origin: jtulach/bck2brwsr

/**
 * Performs the given task, returning its result upon completion.
 * If the computation encounters an unchecked Exception or Error,
 * it is rethrown as the outcome of this invocation.  Rethrown
 * exceptions behave in the same way as regular exceptions, but,
 * when possible, contain stack traces (as displayed for example
 * using {@code ex.printStackTrace()}) of both the current thread
 * as well as the thread actually encountering the exception;
 * minimally only the latter.
 *
 * @param task the task
 * @return the task's result
 * @throws NullPointerException if the task is null
 * @throws RejectedExecutionException if the task cannot be
 *         scheduled for execution
 */
public <T> T invoke(ForkJoinTask<T> task) {
  Thread t = Thread.currentThread();
  if (task == null)
    throw new NullPointerException();
  if (shutdown)
    throw new RejectedExecutionException();
  if ((t instanceof ForkJoinWorkerThread) &&
    ((ForkJoinWorkerThread)t).pool == this)
    return task.invoke();  // bypass submit if in same pool
  else {
    addSubmission(task);
    return task.join();
  }
}

相关文章

ForkJoinPool类方法