Wednesday, March 9, 2016
How toto make LinkedHashMap thread safe?
java.util.Collections.synchronizedMap(map) returns a synchronized (thread-safe) map backed by the specified map.
You can anonymously extend
LinkedHashMap to change the behavior of removeEldestEntry(...), then wrap the instance of the anonymous class in a synchronized map. You didn't mention what type parameters you require, so I'm using <String, Integer> in this example.Map<String, Integer> map = Collections.synchronizedMap(new LinkedHashMap<String, Integer>() {
private static final long serialVersionUID = 12345L; // use something random or just suppress the warning
@Override
protected boolean removeEldestEntry(Entry<String, Integer> eldest) {
return size() > MAX_SIZE; // how many entries you want to keep
}
});
Original Link:http://stackoverflow.com/questions/28653889/java-thread-safe-linkedhashmap-implementation
IOC containers and DI pattern
- http://www.martinfowler.com/articles/injection.html
- http://martinfowler.com/bliki/InversionOfControl.html
- http://stackoverflow.com/questions/6550700/inversion-of-control-vs-dependency-injection
- https://msdn.microsoft.com/en-us/library/aa973811.aspx
- http://buraktas.com/cdi-dependency-injection-producer-method-example/
Tuesday, March 8, 2016
Subscribe to:
Posts (Atom)