Search This Blog

Thread-safe, fixed-size map remove the eldest element automatically

    public static final int MAX_SIZE = 1000;
    Map map = Collections.synchronizedMap(new LinkedHashMap() {
       private static final long serialVersionUID = 12345L; 
       @Override
       protected boolean removeEldestEntry(Entry eldest) {
           return size() > MAX_SIZE;
       }               
    });



See also stackoverflow

  • https://stackoverflow.com/a/28654664
  • https://stackoverflow.com/a/1963881

No comments:

Post a Comment