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

(thread) Need a way to clear all ThreadLocalS of a Thread

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 5.0
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_2000

      Description

      A DESCRIPTION OF THE REQUEST :
      Threads are often reused rather than destroyed and recreated, e.g. in a Thread pooled server. In that case, it would be nice, even necessary, to be able to clear out all ThreadLocalS that were set during the previous use of the Thread so that the Thread is reset to its first-created state. This could be a clearThreadLocals() method on a Thread instance or a static clearAll() method on ThreadLocal class.

      JUSTIFICATION :
      When a Thread is reused by a framework the intent is for it to be as if the Thread were just created. ThreadLocalS should not be left over from the previous use of the Thread.
      Whether or not this type of Thread reuse is a good idea or not, it is in wide use and Java should provide a way to accomodate this usage.


      CUSTOMER SUBMITTED WORKAROUND :
      The only partial workaround is to manually keep track of all ThreadLocals used and set them to null or remove them at the end of the Thread use. This is obviously not optimal, and in many cases, not possible.
      ###@###.### 2005-04-29 06:28:34 GMT

        Attachments

          Activity

            People

            Assignee:
            psoper Pete Soper (Inactive)
            Reporter:
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: