次のクラスは、実際のユースケースに似たものを示しています。同じスレッドに対して常に同じインスタンスを返します。
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();
}
}
どのようにそれを呼びますか?それは「工場」ですか?「バリューホルダー」?「ThreadLocalStore」?