Hi,
In the code below I create a Pen object and initialize it's color to white. In the constructor of Pen, after setting the field 'penColor' to the value passed into the constructor, I update a global static weak hashmap that I'm keeping where the KEY is the 'this pointer - in my case a Pen, and the value is another weakhashmap whose ...
Can the following piece of code be rewritten w/o using Collections.synchronizedMap() yet maintaining correctness at concurrency?
`Collections.synchronizedMap(new WeakHashMap<Class, Object>());`
i.e. is there something from java.util.concurrent one can use instead? Note that merely replacing with
new ConcurrentHashMap<Class, Object>...
I've something like this
private Map<MyObj1, MyObj2> map = new WeakHashMap<MyObj1, MyObj2>();
... somewhere in the code ...
MyObj1 myObj1 = new MyObj1();
map.put(myObj1, new MyObj2();
...
myObj1 = null;
... somewhere else in a thread ... (I would like to pass to a checkThis(MyObj2) method the Value associated with the entry that...
Hi.
I have read many people really like the MapMaker of Google Guava (Collections), however I cannot see any good uses of it.
I have read the javadoc, and it says that it behaves like ConcurrentHashMap. It also says new MapMaker().weakKeys().makeMap() can almost always be used as a drop-in replacement for WeakHashMap.
However, reading...