I came across following code in a legacy system,
private static final ThreadLocal<DateFormat> dateFormatThreadLocal = new ThreadLocal(){
@Override
protected Object initialValue() {
//Set initial value
return new SimpleDateFormat("");
}
};
private static final DateFormat someValue = dateFormatThreadLocal.get();
However, I have following questions.
1.) Is it a good idea to define thread locals as final. ( I know static is fine)
2.) Is it a good idea to hold thread local.get() call in a static (or both static and final) instance variable? ( if we do this doesn't it hinder the whole purpose of having thread-local at first place )