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

Allow custom thread name prefix on Executor threads

    Details

    • Type: Enhancement
    • Status: Open
    • Priority: P3
    • Resolution: Unresolved
    • Affects Version/s: 7, 9
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      A DESCRIPTION OF THE REQUEST :
      Currently the threads that come out of Executors class insist on naming their own threads. There's some logic to that as the thread name needs to be fairly unique in order to be meaningful so in the default ThreadFactory implementation in the JDK threads will be named " pool-N-thread-M " .

      For anybody looking at the threads these names are not very meaningful.

      The proposal is to be able to easily customize the thread name prefix, i.e. the " pool " part.



      JUSTIFICATION :
      Currently the only way to do this is to lift out the DefaultThreadFactory code from the JDK and create your own ThreadFactory based on that which is then enhanced to support a custom thread name prefix. That method is not desirable. I don't want to replicate code from JDK. I use the Java Concurrency classes in order to *not* to have to deal with stuff like that. I want my code to always be able to benefit from whatever enhancements to DefaultThreadFactory that will come with future versions of the JDK,

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Possibly the best and easiest way so solve would simply be to create extra " new " methods in the Executors class that would accept 'threadNamePrefix' as an argument.

      Example:

      Executors.newCachedThreadPool(String threadNamePrefix)
      Executors.newCachedThreadPool(ThreadFactory threadFactory, String threadNamePrefix)


      etc.


      Note that there may be other solutions to the problem than the one described here. Bottom line is that in concurrent systems naming threads seems to be a common requirement so it should be easy to do in Java Concurrency classes and without having to replicate code from the JDK.
      ACTUAL -
      Thread name prefix cannot be customized without lifting out source code from the JDK.

      CUSTOMER SUBMITTED WORKAROUND :
      Lift out the source code for DefaultThreadFactory from the JDK and customize that to allow the thread name prefix to be customizable.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated: