java - 设计模式名称: Is it a factory?

标签 java design-patterns naming-conventions factory-pattern thread-local

下面的类显示了与真实用例类似的内容。它始终为同一线程返回相同的实例。

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

}

你会怎么调用它?是“工厂”吗? “值(value)持有者”? “ThreadLocalStore”?

最佳答案

有些人简单地将其称为 ThreadLocal Pattern 。另一个已知名称是 Thread-local Storage (TLS) .

关于java - 设计模式名称: Is it a factory?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3457753/

相关文章:

c++ - 减少实体组件系统中的 Duck-typing 劣势

java - REST API 调用是否应该在存储库层上使用 @Repository 进行?

java - 独立 Java 程序的数据库连接池

java - Spring中使用Map进行绑定(bind) - Thymeleaf

java - 斯坦福 CoreNLP : input with one sentence per line

oop - 当编程语言使用驼峰命名法时,PostgreSQL 标识符中的下划线或驼峰命名法?

django - Django View 的命名约定?

java - 为什么 Android Handler 's post method doesn' t 存在?

java - 重构基于 boolean 的流程

android - 布局文件命名约定?