Maintaining unique objects for names with concurrent delete
问题 I am using the following programming idiom. I keep a synchronized HashMap with an association of names to objects. To lookup an object for a name I use the following code: MyObject getObject(String name) { synchronized(map) { MyObject obj = map.get(name); if (obj == null) { obj = new MyObjec(); map.put(name, obj); } } } When I then want to work exclusively on such an object I will use a synchronized on such an object: synchronized(obj) { /* do something exclusively on obj (work type I) */ }