public static void main(String[] args) throws Exception { ForkJoinPool pool = new ForkJoinPool(); // 提交可分解的PrintTask任务 pool.submit(new PrintTask(0, 600)); pool.awaitTermination(2, TimeUnit.SECONDS); // 关闭线程池 pool.shutdown(); }
public static void main(String[] args) throws Exception { procs = 0; int num = 45; try { if (args.length > 0) procs = Integer.parseInt(args[0]); if (args.length > 1) num = Integer.parseInt(args[1]); } catch (Exception e) { System.out.println("Usage: java DynamicFib <threads> <number>"); return; } for (int reps = 0; reps < 2; ++reps) { ForkJoinPool pool = (procs == 0) ? new ForkJoinPool() : new ForkJoinPool(procs); for (int i = 0; i < 20; ++i) test(pool, num); System.out.println(pool); pool.shutdown(); } }