本文整理了Java中java.util.concurrent.ForkJoinPool.tryAwaitWork()
方法的一些代码示例,展示了ForkJoinPool.tryAwaitWork()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ForkJoinPool.tryAwaitWork()
方法的具体详情如下:
包路径:java.util.concurrent.ForkJoinPool
类名称:ForkJoinPool
方法名:tryAwaitWork
[英]Tries to enqueue worker w in wait queue and await change in worker's eventCount. If the pool is quiescent and there is more than one worker, possibly terminates worker upon exit. Otherwise, before blocking, rescans queues to avoid missed signals. Upon finding work, releases at least one worker (which may be the current worker). Rescans restart upon detected staleness or failure to release due to contention. Note the unusual conventions about Thread.interrupt here and elsewhere: Because interrupts are used solely to alert threads to check termination, which is checked here anyway, we clear status (using Thread.interrupted) before any call to park, so that park does not immediately return due to status being set via some other unrelated call to interrupt in user code.
[中]尝试将工作程序w排入等待队列,并等待工作程序事件计数的更改。如果池处于静止状态且有多个工作进程,则可能在退出时终止工作进程。否则,在阻塞之前,请重新扫描队列以避免错过信号。找到工作后,释放至少一个工作人员(可能是当前工作人员)。在检测到因争用而导致的过时或释放失败时重新扫描。注意关于线程的不寻常约定。在此处和其他地方中断:由于中断仅用于提醒线程检查终止(此处无论如何都会检查终止),因此在调用park之前,我们会清除状态(使用Thread.interrupted),这样park不会立即返回,因为状态是通过用户代码中的其他无关中断调用设置的。
代码示例来源:origin: org.apidesign.bck2brwsr/emul
/**
* Top-level loop for worker threads: On each step: if the
* previous step swept through all queues and found no tasks, or
* there are excess threads, then possibly blocks. Otherwise,
* scans for and, if found, executes a task. Returns when pool
* and/or worker terminate.
*
* @param w the worker
*/
final void work(ForkJoinWorkerThread w) {
boolean swept = false; // true on empty scans
long c;
while (!w.terminate && (int)(c = ctl) >= 0) {
int a; // active count
if (!swept && (a = (int)(c >> AC_SHIFT)) <= 0)
swept = scan(w, a);
else if (tryAwaitWork(w, c))
swept = false;
}
}
代码示例来源:origin: jtulach/bck2brwsr
/**
* Top-level loop for worker threads: On each step: if the
* previous step swept through all queues and found no tasks, or
* there are excess threads, then possibly blocks. Otherwise,
* scans for and, if found, executes a task. Returns when pool
* and/or worker terminate.
*
* @param w the worker
*/
final void work(ForkJoinWorkerThread w) {
boolean swept = false; // true on empty scans
long c;
while (!w.terminate && (int)(c = ctl) >= 0) {
int a; // active count
if (!swept && (a = (int)(c >> AC_SHIFT)) <= 0)
swept = scan(w, a);
else if (tryAwaitWork(w, c))
swept = false;
}
}
代码示例来源:origin: org.codehaus.jsr166-mirror/jsr166
/**
* Top-level loop for worker threads: On each step: if the
* previous step swept through all queues and found no tasks, or
* there are excess threads, then possibly blocks. Otherwise,
* scans for and, if found, executes a task. Returns when pool
* and/or worker terminate.
*
* @param w the worker
*/
final void work(ForkJoinWorkerThread w) {
boolean swept = false; // true on empty scans
long c;
while (!w.terminate && (int)(c = ctl) >= 0) {
int a; // active count
if (!swept && (a = (int)(c >> AC_SHIFT)) <= 0)
swept = scan(w, a);
else if (tryAwaitWork(w, c))
swept = false;
}
}
内容来源于网络,如有侵权,请联系作者删除!