The following class shows something similar to a real use case. It returns always the same instance for the same thread.
public class LookingForName {
private static final ThreadLocal<Something> threadLocal =
new ThreadLocal<Something>(){
@Override
protected Something initialValue() {
return getSomethingSpecial(); // not relevant
}
};
/**
* @return always the same instance of "Something" for the current thread.
*/
public static Something getInstance() {
return threadLocal.get();
}
}
How would you call it? Is it a "factory"? A "value holder"? "ThreadLocalStore"?