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

Clarify ForkJoinPool.getStealCount() javadoc

    Details

      Description

      ADDITIONAL SYSTEM INFORMATION :
      JAVA 8 OSX

      A DESCRIPTION OF THE PROBLEM :
      The method forkJoinPool.getStealCount() returns wrong number returns the total tasks submitted always and not the steal count

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the code provided.

      The code shows that the steal count is always 99

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      It should give the proper steal count and not the total tasks submitted.
      Expected is some random number based on stealing.
      ACTUAL -
      99 always

      ---------- BEGIN SOURCE ----------
      package com.learn.java;

      import org.python.antlr.ast.For;

      import java.util.ArrayList;
      import java.util.List;
      import java.util.concurrent.*;

      public class TestCompletableFuturePool {

          private static ForkJoinPool forkJoinPool= ForkJoinPool.commonPool();//new ForkJoinPool(2);//

          public static void main(String[] args) throws ExecutionException, InterruptedException {
              ExecutorService executorService = Executors.newFixedThreadPool(1);
              final List<Integer> val = new ArrayList<>();
              Runnable r = ()-> getstat();
              new Thread(r).start();


              for (int i = 0; i < 100; i++) {
                  CompletableFuture<String> stringCf = CompletableFuture.supplyAsync(() -> {
                      try {
                      // System.out.println(Thread.currentThread().getName());
                          double x =0.0;
                          for ( long temp =1;temp<99999999L;temp++){
                               x = temp /2 + temp *2 + Math.sqrt(temp);

                          }
                          System.out.println(Thread.currentThread().getName() + " --> " + x);
                      } catch (Exception e) {
                          e.printStackTrace();
                      }

                      return "done";

                  },forkJoinPool).thenApply( x-> {
                      return x.toUpperCase(); });

            // System.out.println(stringCf.get().toString());





              }


              Thread.sleep(10000);
              executorService.shutdownNow();

          }

          private static void getstat() {

              while (true) {
                  try {
                      Thread.sleep(1000);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
                  System.out.println("+++++++++++++++++++++++++++++++++++++++++");

                  int queuedSubmissionCount = forkJoinPool.getQueuedSubmissionCount();
                  long queuedTaskCount = forkJoinPool.getQueuedTaskCount();

                  int poolSize = forkJoinPool.getPoolSize();

                  int activeThreadCount = forkJoinPool.getActiveThreadCount();
                  long stealCount = forkJoinPool.getStealCount();
                  int runningThreadCount = forkJoinPool.getRunningThreadCount();
                  int parallelism = forkJoinPool.getParallelism();

                  System.out.println(" queuedSubmissionCount " + queuedSubmissionCount);
                  System.out.println(" queuedTaskCount " + queuedTaskCount);
                  System.out.println("poolSize " + poolSize);
                  System.out.println(" activeThreadCount " + activeThreadCount);
                  System.out.println("stealCount " + stealCount);
                  System.out.println(" runningThreadCount " + runningThreadCount);
                  System.out.println("parallelism " + parallelism);
                  if(queuedSubmissionCount ==0)
                      break;

              }
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      No need for workaround as this impacts only metrics.

      FREQUENCY : always


        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved: