betterattributestore.java

来自「java concurrency in practice 源码. JAVA」· Java 代码 · 共 32 行

JAVA
32
字号
package net.jcip.examples;import java.util.*;import java.util.regex.*;import net.jcip.annotations.*;/** * BetterAttributeStore * <p/> * Reducing lock duration * * @author Brian Goetz and Tim Peierls */@ThreadSafepublic class BetterAttributeStore {    @GuardedBy("this") private final Map<String, String>            attributes = new HashMap<String, String>();    public boolean userLocationMatches(String name, String regexp) {        String key = "users." + name + ".location";        String location;        synchronized (this) {            location = attributes.get(key);        }        if (location == null)            return false;        else            return Pattern.matches(regexp, location);    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?