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

Cancellation problem when using the nested future with the same timeout

XMLWordPrintable

      ADDITIONAL SYSTEM INFORMATION :
      java version "11.0.2" 2019-01-15 LTS
      Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
      Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)

      A DESCRIPTION OF THE PROBLEM :
      If the Future is nested for different jobs is created and given the same timeout for both Future, the main Future is not canceled. But if the timeout for the child Future is less than the main Future, it can be canceled.

      REGRESSION : Last worked in version 11.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Example:
      public static void main(String[] args) {
          ExecutorService service = Executors.newCachedThreadPool();

          Future<Object> main= service.submit(()->{
              Future<Object> child= service.submit(()->{
                  while(!Thread.currentThread().isInterrupted()){
                      System.out.println("child future is running...");
                      Thread.sleep(100);
                  }
                  return 0;
              });
              try{
                  child.get(10,TimeUnit.MILLISECONDS);
              }catch(Exception we){
                  System.out.println("child future cancelled.");
                  child.cancel(true);
              }
              while(!Thread.currentThread().isInterrupted()){
                  System.out.println("main future is running...");
                  Thread.sleep(100);
              }
              return 0;
          });
          try{
              main.get(10,TimeUnit.MILLISECONDS);
          }catch(Exception we){
              System.out.println("main future cancelled.");
              main.cancel(true);
          }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      main future cancelled.
      child future cancelled.
      ACTUAL -
      main future cancelled.
      child future cancelled.
      main future is running...
      main future is running...
      main future is running...
      main future is running...
      main future is running...

      FREQUENCY : always


            martin Martin Buchholz
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: