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

InnocuousThreadFactory uses wrong priority for threads in CleanerImpl

XMLWordPrintable

    • b09
    • generic
    • generic

      A DESCRIPTION OF THE PROBLEM :
      During refactoring, the priority was changed from Thread.MAX_PRIORITY - 2 to instead state Thread.MIN_PRIORITY - 2, which results in a negative priority, and is thus set to Thread.NORM_PRIORITY. Thus the Cleaner by default now has threads with priority 5, instead of 8.

      The change was done in git revision # 992b50087d2ec8878dfcbbd1820a00b6b6bdf644 and label 8261036 by Claes Redestad

      REGRESSION : Last worked in version 16.0.2

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the class below with Java 16.0.2 and Java 17

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      My cleaner thread priority is 8
      ACTUAL -
      My cleaner thread priority is 5

      ---------- BEGIN SOURCE ----------
      import java.lang.ref.*;

      public class CleanerDemo {
          public static void main(String... args) throws InterruptedException {
              Cleaner cleaner = Cleaner.create();
              Cleaner.Cleanable cleanable = cleaner.register(new Object(),
                      () -> System.out.println("My cleaner thread priority is " +
                              Thread.currentThread().getPriority()));
              System.gc();
              Thread.sleep(1000);
          }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      It is not a serious bug, since thread priorities are usually of not much significance. However, one could provide a thread factory with a different priority.

      FREQUENCY : always


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

              Created:
              Updated:
              Resolved: