예제 #1
0
 /** pollSubmission returns unexecuted submitted task, if present */
 public void testPollSubmission() {
   final CountDownLatch done = new CountDownLatch(1);
   SubFJP p = new SubFJP();
   try (PoolCleaner cleaner = cleaner(p)) {
     ForkJoinTask a = p.submit(awaiter(done));
     ForkJoinTask b = p.submit(awaiter(done));
     ForkJoinTask c = p.submit(awaiter(done));
     ForkJoinTask r = p.pollSubmission();
     assertTrue(r == a || r == b || r == c);
     assertFalse(r.isDone());
     done.countDown();
   }
 }
예제 #2
0
 /** drainTasksTo transfers unexecuted submitted tasks, if present */
 public void testDrainTasksTo() {
   final CountDownLatch done = new CountDownLatch(1);
   SubFJP p = new SubFJP();
   try (PoolCleaner cleaner = cleaner(p)) {
     ForkJoinTask a = p.submit(awaiter(done));
     ForkJoinTask b = p.submit(awaiter(done));
     ForkJoinTask c = p.submit(awaiter(done));
     ArrayList<ForkJoinTask> al = new ArrayList();
     p.drainTasksTo(al);
     assertTrue(al.size() > 0);
     for (ForkJoinTask r : al) {
       assertTrue(r == a || r == b || r == c);
       assertFalse(r.isDone());
     }
     done.countDown();
   }
 }