Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在ForkJoinPool中中断ForkJoinTasks?_Java_Android_Interrupt_Forkjoinpool - Fatal编程技术网

Java 如何在ForkJoinPool中中断ForkJoinTasks?

Java 如何在ForkJoinPool中中断ForkJoinTasks?,java,android,interrupt,forkjoinpool,Java,Android,Interrupt,Forkjoinpool,例如,有一个的LinkedList。然后我期待结果: 第一种方式: for (ForkJoinTask task: subTasks) { task.join (); // how interrupt? } 第二种方式: for (ForkJoinTask task: subTasks) { try { task.get (); // how interrupt, InterruptedException not thrown, because Thread.

例如,有一个的
LinkedList
。然后我期待结果:

第一种方式:

for (ForkJoinTask task: subTasks) {
    task.join ();  // how interrupt?
}
第二种方式:

for (ForkJoinTask task: subTasks) {
    try {
       task.get ();  // how interrupt, InterruptedException not thrown, because Thread.currentThread() instanceof ForkJoinWorkerThread ?
    } catch (ExecutionException | InterruptedException ignored) {}
}
在第二种情况下,该命令指向该命令,并且不会引发异常


我如何打断这些期望:task.join或task.get。

你能解释一下你想要实现什么吗?如果任务耗时太长或出现其他情况,是否要取消任务?我已经解释过了。>其他条件