admin 管理员组文章数量: 1086019
2024年1月17日发(作者:薄荷的个人博客)
import iveAction;public class ExceptionTask extends RecursiveAction{
private static final long serialVersionUID = -1748233L;
private static final int THRESHOLD = 10;// 阈值
private int begin;
private int end;
public ExceptionTask(int begin, int end) { super(); = begin; = end; } @Override protected void compute() { if (begin-end
invokeAll(new ExceptionTask(begin, mid), new ExceptionTask(mid+1, end)); } }} 测试
import ;import ionException;import inPool;import inTask;import it;import ;public class ExceptionTaskTest { @Test public void test() throws InterruptedException { ForkJoinPool forkJoinPool = new ForkJoinPool();
int[] a = new int[10]; Random random = new Random(); for (int i = 0; i < ; i++) { a[i] = t(99); } ExceptionTask task = new ExceptionTask(0, -1); ForkJoinTask
ermination(3, S); if (letedAbnormally()) { n("an exception has been throwed"); n(eption()); }else { n("no exception"); }
wn(); }} 结果为:
ionException: eException: eException: test exception at (:942) at (:38) at 0(Native Method) at (:57) at (:43) at (:606) at orkMethod$lectiveCall(:44) at (:15) at Explosively(:41) at te(:20) at Ignored(:79) at ld(:71) at ld(:49) at Runner$(:193) at Runner$le(:52) at ldren(:191) at $000(:42) at Runner$te(:184) at (:236) at (:50) at (:38) at ts(:467) at ts(:683) at (:390) at (:197)Caused by: eException: test exception at e(:25) at (:177) at (:334) at sk(:604) at (:784) at (:646) at (:398)an exception has been eException: eException: test exception
版权声明:本文标题:ForkJoin中的异常处理 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1705435639a484680.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论