title: ThreadLocal Resource Leak and WeakReference
body: <p>My limited understanding of <a href="http://java.sun.com/javase/6/docs/api/java/lang/ThreadLocal.html" rel="noreferrer">ThreadLocal</a> is that it has <a href="http://www.google.com/search?q=threadlocal+leak" rel="noreferrer">resource leak issues</a>. I gather  this problem can be remedied through proper use of <a href="http://java.sun.com/javase/6/docs/api/java/lang/ref/WeakReference.html" rel="noreferrer">WeakReferences</a> with ThreadLocal (although I may have misunderstood this point.) I would simply like a pattern or example for correctly using ThreadLocal with WeakReference, if one exists. For instance, in this code snippet where would the WeakReference be introduced?</p>
  
  <pre><code>static class DateTimeFormatter {
      private static final ThreadLocal&lt;SimpleDateFormat&gt; DATE_PARSER_THREAD_LOCAL = new ThreadLocal&lt;SimpleDateFormat&gt;() {
          protected SimpleDateFormat initialValue() {
              return new SimpleDateFormat("yyyy/MM/dd HH:mmz");
          }
      };
      public String format(final Date date) {
          return DATE_PARSER_THREAD_LOCAL.get().format(date);
      }
      public Date parse(final String date) throws ParseException
      {
        return DATE_PARSER_THREAD_LOCAL.get().parse(date);
      }
  }
  </code></pre>