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

ScheduledThreadPoolExecutor.shutdownNow() returns cancelled tasks

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Won't Fix
    • Affects Version/s: 6
    • Fix Version/s: None
    • Component/s: tools
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version " 1.6.0_27 "
      Java(TM) SE Runtime Environment (build 1.6.0_27-b07)
      Java HotSpot(TM) 64-Bit Server VM (build 20.2-b06, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Linux xxxxx 2.6.32-131.4.1.el6.x86_64 #1 SMP Fri Jun 10 10:54:26 EDT 2011 x86_64 x86_64 x86_64 GNU/Linux


      A DESCRIPTION OF THE PROBLEM :
      ScheduledThreadPoolExecutor.shutdownNow() returns cancelled tasks as though they were still due to be executed.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a ScheduledThreadPoolExecutor. Schedule a task far in the future. Cancel it. Call shutdownNow(). Even though the task has been cancelled, it is returned in the list of yet-to-be-executed tasks.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The list returned by shutdownNow() should be empty, since it should contain only tasks neither executed nor cancelled.
      ACTUAL -
      The list contains tasks that were cancelled.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.util.concurrent.ScheduledFuture;
      import java.util.concurrent.ScheduledThreadPoolExecutor;
      import java.util.concurrent.TimeUnit;
      import java.util.List;

      public class TestShutdownNow {

          public static void main(String[] argv) throws Exception {
      ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor(1);

      Runnable task = new Runnable() {
      public void run() {

      }
          };
      ScheduledFuture<?> future = scheduler.schedule(task, 999, TimeUnit.DAYS);
      if (!future.cancel(false)) {
          throw new Exception( " cancel failed " );
      }

      List<Runnable> pending = scheduler.shutdownNow();
      if (pending.size() != 0) {
          throw new Exception( " shutdownNow() returned " + pending.size() + " tasks instead of zero " );
      }
          }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Calling shutdown() before shutdownNow() will purge the internal list of tasks such that shutdownNow() will correctly return an empty list.

        Attachments

          Activity

            People

            Assignee:
            aefimov Aleksej Efimov
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: