设计模式名称:它是工厂吗?

dea*_*mon 0 java design-patterns naming-conventions thread-local factory-pattern

以下类显示了与实际用例类似的内容.它始终为同一个线程返回相同的实例.

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();
    }

}
Run Code Online (Sandbox Code Playgroud)

你怎么称呼它?它是"工厂"吗?"价值持有者"?"ThreadLocalStore"?

And*_*s_D 6

有些人简单地称它为ThreadLocal Pattern.另一个已知名称是线程局部存储(TLS).