一种可能的(并且是常见的)用法是,当你有一些不是线程安全的对象,但又希望避免同步对该对象的访问时(我正在看着你,SimpleDateFormat)。而是给每个线程自己的对象实例。
例如:
public class Foo{ // SimpleDateFormat is not thread-safe, so give one to each thread private static final ThreadLocal<SimpleDateFormat> formatter = new ThreadLocal<SimpleDateFormat>(){ @Override protected SimpleDateFormat initialValue() { return new SimpleDateFormat("yyyyMMdd HHmm"); } }; public String formatIt(Date date) { return formatter.get().format(date); }}


