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

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

本文整理了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

  1. /**
  2. * Unless terminating, forks task if within an ongoing FJ
  3. * computation in the current pool, else submits as external task.
  4. */
  5. private <T> void forkOrSubmit(ForkJoinTask<T> task) {
  6. ForkJoinWorkerThread w;
  7. Thread t = Thread.currentThread();
  8. if (shutdown)
  9. throw new RejectedExecutionException();
  10. if ((t instanceof ForkJoinWorkerThread) &&
  11. (w = (ForkJoinWorkerThread)t).pool == this)
  12. w.pushTask(task);
  13. else
  14. addSubmission(task);
  15. }

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

  1. /**
  2. * Unless terminating, forks task if within an ongoing FJ
  3. * computation in the current pool, else submits as external task.
  4. */
  5. private <T> void forkOrSubmit(ForkJoinTask<T> task) {
  6. ForkJoinWorkerThread w;
  7. Thread t = Thread.currentThread();
  8. if (shutdown)
  9. throw new RejectedExecutionException();
  10. if ((t instanceof ForkJoinWorkerThread) &&
  11. (w = (ForkJoinWorkerThread)t).pool == this)
  12. w.pushTask(task);
  13. else
  14. addSubmission(task);
  15. }

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

  1. /**
  2. * Unless terminating, forks task if within an ongoing FJ
  3. * computation in the current pool, else submits as external task.
  4. */
  5. private <T> void forkOrSubmit(ForkJoinTask<T> task) {
  6. ForkJoinWorkerThread w;
  7. Thread t = Thread.currentThread();
  8. if (shutdown)
  9. throw new RejectedExecutionException();
  10. if ((t instanceof ForkJoinWorkerThread) &&
  11. (w = (ForkJoinWorkerThread)t).pool == this)
  12. w.pushTask(task);
  13. else
  14. addSubmission(task);
  15. }

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

  1. /**
  2. * Performs the given task, returning its result upon completion.
  3. * If the computation encounters an unchecked Exception or Error,
  4. * it is rethrown as the outcome of this invocation. Rethrown
  5. * exceptions behave in the same way as regular exceptions, but,
  6. * when possible, contain stack traces (as displayed for example
  7. * using {@code ex.printStackTrace()}) of both the current thread
  8. * as well as the thread actually encountering the exception;
  9. * minimally only the latter.
  10. *
  11. * @param task the task
  12. * @return the task's result
  13. * @throws NullPointerException if the task is null
  14. * @throws RejectedExecutionException if the task cannot be
  15. * scheduled for execution
  16. */
  17. public <T> T invoke(ForkJoinTask<T> task) {
  18. Thread t = Thread.currentThread();
  19. if (task == null)
  20. throw new NullPointerException();
  21. if (shutdown)
  22. throw new RejectedExecutionException();
  23. if ((t instanceof ForkJoinWorkerThread) &&
  24. ((ForkJoinWorkerThread)t).pool == this)
  25. return task.invoke(); // bypass submit if in same pool
  26. else {
  27. addSubmission(task);
  28. return task.join();
  29. }
  30. }

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

  1. /**
  2. * Performs the given task, returning its result upon completion.
  3. * If the computation encounters an unchecked Exception or Error,
  4. * it is rethrown as the outcome of this invocation. Rethrown
  5. * exceptions behave in the same way as regular exceptions, but,
  6. * when possible, contain stack traces (as displayed for example
  7. * using {@code ex.printStackTrace()}) of both the current thread
  8. * as well as the thread actually encountering the exception;
  9. * minimally only the latter.
  10. *
  11. * @param task the task
  12. * @return the task's result
  13. * @throws NullPointerException if the task is null
  14. * @throws RejectedExecutionException if the task cannot be
  15. * scheduled for execution
  16. */
  17. public <T> T invoke(ForkJoinTask<T> task) {
  18. Thread t = Thread.currentThread();
  19. if (task == null)
  20. throw new NullPointerException();
  21. if (shutdown)
  22. throw new RejectedExecutionException();
  23. if ((t instanceof ForkJoinWorkerThread) &&
  24. ((ForkJoinWorkerThread)t).pool == this)
  25. return task.invoke(); // bypass submit if in same pool
  26. else {
  27. addSubmission(task);
  28. return task.join();
  29. }
  30. }

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

  1. /**
  2. * Performs the given task, returning its result upon completion.
  3. * If the computation encounters an unchecked Exception or Error,
  4. * it is rethrown as the outcome of this invocation. Rethrown
  5. * exceptions behave in the same way as regular exceptions, but,
  6. * when possible, contain stack traces (as displayed for example
  7. * using {@code ex.printStackTrace()}) of both the current thread
  8. * as well as the thread actually encountering the exception;
  9. * minimally only the latter.
  10. *
  11. * @param task the task
  12. * @return the task's result
  13. * @throws NullPointerException if the task is null
  14. * @throws RejectedExecutionException if the task cannot be
  15. * scheduled for execution
  16. */
  17. public <T> T invoke(ForkJoinTask<T> task) {
  18. Thread t = Thread.currentThread();
  19. if (task == null)
  20. throw new NullPointerException();
  21. if (shutdown)
  22. throw new RejectedExecutionException();
  23. if ((t instanceof ForkJoinWorkerThread) &&
  24. ((ForkJoinWorkerThread)t).pool == this)
  25. return task.invoke(); // bypass submit if in same pool
  26. else {
  27. addSubmission(task);
  28. return task.join();
  29. }
  30. }

相关文章

ForkJoinPool类方法