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

Task may stay in the queues of ForkJoinPool forever When you shutdown

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8u144
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      FULL PRODUCT VERSION :
      java version "1.8.0_144"
      Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [版本 10.0.10586]

      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.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      first: take two breakpoints in the lines [2359] [2224] of the ForkJoinPool.
      2359 U.putOrderedObject(a, j, task);
      2224 rs = lockRunState(); // enter SHUTDOWN phase

      let the 'printHelloWorld' thread just before into queue.
      and let the 'shutdownPool' thread just before take the runState turn to SHUTDOWN.

      second: debug the given source code, and let the 'shutdownPool' suspended on the line [2224] go first, 'printHelloWorld' suspended on the line [2359] go second。

      and you can see No output of ‘Hello,world’, No exceptions throw, the 'printHelloWorld' thread forever blocked.....

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      output of ‘Hello,world’ or exceptions throw.
      ACTUAL -
      No output of ‘Hello,world’, No exceptions throw, the 'printHelloWorld' thread forever blocked

      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(){
      ForkJoinTask<String> task = pool.submit(new Callable<String>(){
      public String call(){
      return "Hello,world";
      }
      });
      //输出 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(); }
      };
      // Thread.sleep(1000);
      new Thread(){
      public void run(){
      pool.shutdown();
      }
      { this.setName("shutdownPool");this.start(); }
      };
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      2359 U.putOrderedObject(a, j, task);
      ++++ if ((rs = runState) < 0) { // tail scan...
      ++++ U.putOrderedObject(a, j, null);
      ++++ tryTerminate(false, false); // help terminate
      ++++ throw new RejectedExecutionException();
      ++++ }
      2365 U.putOrderedInt(q, QTOP, s + 1);

      just look at runState again, after enter the queue

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: