3 responses

  1. Andrew
    July 30, 2013

    I’d recommend using ThreadLocal.remove(), not ThreadLocal.set(null). This way when you call ThreadLocal.get() again in the same thread, the initialValue() method will automatically be called, and the new instance will be created.

    • Nancy Deschênes
      July 30, 2013

      Good point. In my experience with ThreadLocals in a thread pool setting, I’ve always set the value by hand so this has not come up, but in a situation where you rely on initialValue(), it makes sense

      Thank you for bringing it up.

Leave a Reply




Back to top
mobile desktop