Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6314788

Tasks resubmitted to a ThreadPoolExecutor may fail to execute

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6
    • Fix Version/s: 6
    • Component/s: core-libs
    • Labels:

      Description

      Doug Lea writes:

      Re-submitting a task that is rejected but has also been
      previously successfully accepted may cause an instance of that task
      not to be run.

      Test program:


      import java.util.concurrent.*;
      import java.util.concurrent.atomic.*;

      public class RecycledTPETask {
           public static void main(String[] args) throws Exception {
               final int nTasks = 1000;
               final AtomicInteger nRun = new AtomicInteger(0);
               final Runnable recycledTask = new Runnable() {
                       public void run() {
                           nRun.getAndIncrement();
                       } };
               final ThreadPoolExecutor p =
                   new ThreadPoolExecutor(1, 30, 60, TimeUnit.SECONDS,
                                          new ArrayBlockingQueue(30));
               try {
                   for (int i = 0; i < nTasks; ++i) {
                       for (;;) {
                           try {
                               p.execute(recycledTask);
                               break;
                           }
                           catch (RejectedExecutionException ignore) {
                           }
                       }
                   }
                   Thread.sleep(5000); // enough time to run all tasks
                   if (nRun.get() < nTasks)
                       throw new Error("Started " + nTasks +
                                       " Ran " + nRun.get());
               } catch(Exception ex) {
                   ex.printStackTrace();
               } finally {
                   p.shutdown();
               }
           }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                martin Martin Buchholz
                Reporter:
                martin Martin Buchholz
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: