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"?
| 归档时间: |
|
| 查看次数: |
610 次 |
| 最近记录: |