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>>1;

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 result = (task); try { (); } catch (ExecutionException e) { tackTrace(); }

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


本文标签: 薄荷 时候 作者 抛出