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

Task may stay in the queues forever when shutdown (ForkJoinPool jdk9)

    Details

      Description

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      when submit a task to the ForkJoinPool,if the ForkJoinPool is shutdown,but the submit operation haven't seen the ‘shutdown’, and it go on into the queue after the ForkJoinPool turn to 'shutdown' operation and scan&cleanup the queues.....then, the shutdown operation think of completing the cleanup, the submit operation is stay forever in the queue.the outer's get operation is forever blocked.
      the bug is like it in jdk 8,but because the changes of implementations between jdk9 and jdk8,this bug is not the same as jdk8 and the two bugs lead to the same result。
      I will give the test case source codes below.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      first: take the two breakpoints in line[1914]&[2088] in the ForkJoinPoll.
      1914: a[(al - 1) & s] = task;
      2088: MODE.compareAndSet(this, md, md | SHUTDOWN);

      second: perform the source codes.
      you will see the 'Hello,world first' has been print out.

      third: let's the line[2088] of 'shutdownPool' thread go first, let's the line[1914] of 'printHelloWorld' thread go second.

      then, we can't see the 'Hello,world second' be print out....the 'printHelloWorld' thread blocking forever.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
       'Hello,world second' be print out, or throws exception
      ACTUAL -
      we can't see the 'Hello,world second' be print out....the 'printHelloWorld' thread blocking forever

      REPRODUCIBILITY :
      This bug can be reproduced occasionally.

      ---------- BEGIN SOURCE ----------
      package com.psly;

      import java.util.concurrent.Callable;
      import java.util.concurrent.ExecutionException;
      import java.util.concurrent.ForkJoinPool;
      import java.util.concurrent.ForkJoinTask;
      public class TestForkJoin {
      public static void main(String[] args) throws InterruptedException {
      // TODO Auto-generated method stub
      ForkJoinPool pool = new ForkJoinPool();
      new Thread(){
      public void run(){
      pool.submit(new Runnable(){
      public void run(){
      System.out.println("Hello,world first");
      }
      });

      ForkJoinTask<String> task = pool.submit(new Callable<String>(){
      public String call(){
      return "Hello,world second";
      }
      });
      //输出 Hello,world (永远不会输出,也不会报异常, 所以这是个bug)
      try {
      System.out.println(task.get());
      } catch (InterruptedException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      } catch (ExecutionException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
      }
      }
      { this.setName("printHelloWorld");this.start(); }
      };
      new Thread(){
      public void run(){
      pool.shutdown();
      }
      { this.setName("shutdownPool");this.start(); }
      };
      }
      }
      ---------- END SOURCE ----------

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: