我正在学习多线程,并且在与LinkedHashMap
一起工作时,尤其是关于我的代码(锁定)时,难以理解同步。从proxyAutoMap
检索到的对象被锁定了吗?还是整个proxyAutoMap
实例都被锁定了?
注意:AutoMap
只是用于存储对象的LinkedHashMap
哈希图
下面是一些代码供参考:
public abstract class ProxyAutomobile {
protected static AutoMap<Automobile> proxyAutoMap = new AutoMap<Automobile>();
public void printAuto(String key) {
try {
synchronized (proxyAutoMap.getAuto(key)) {
proxyAutoMap.getAuto(key).print();
}
} catch (AutoException ae ) {
ae.fix(ae.getErrorID());
}
}
}