public String intern(String input) { String result = get(input); if (result != null) { return result; } /* 18-Sep-2013, tatu: We used to use LinkedHashMap, which has simple LRU * method. No such functionality exists with CHM; and let's use simplest * possible limitation: just clear all contents. This because otherwise * we are simply likely to keep on clearing same, commonly used entries. */ if (size() >= MAX_ENTRIES) { /* Not incorrect wrt well-known double-locking anti-pattern because underlying * storage gives close enough answer to real one here; and we are * more concerned with flooding than starvation. */ synchronized (lock) { if (size() >= MAX_ENTRIES) { clear(); } } } result = input.intern(); put(result, result); return result; } }
public String intern(String input) { String result = get(input); if (result != null) { return result; } /* 18-Sep-2013, tatu: We used to use LinkedHashMap, which has simple LRU * method. No such functionality exists with CHM; and let's use simplest * possible limitation: just clear all contents. This because otherwise * we are simply likely to keep on clearing same, commonly used entries. */ if (size() >= MAX_ENTRIES) { /* Not incorrect wrt well-known double-locking anti-pattern because underlying * storage gives close enough answer to real one here; and we are * more concerned with flooding than starvation. */ synchronized (lock) { if (size() >= MAX_ENTRIES) { clear(); } } } result = input.intern(); put(result, result); return result; } }
@Override protected boolean removeEldestEntry(Map.Entry<String,String> eldest) { return size() > MAX_ENTRIES; }
@Override protected boolean removeEldestEntry(Map.Entry<String,String> eldest) { return size() > MAX_ENTRIES; }
public String intern(String input) { String result = get(input); if (result != null) { return result; } /* 18-Sep-2013, tatu: We used to use LinkedHashMap, which has simple LRU * method. No such functionality exists with CHM; and let's use simplest * possible limitation: just clear all contents. This because otherwise * we are simply likely to keep on clearing same, commonly used entries. */ if (size() >= MAX_ENTRIES) { /* Not incorrect wrt well-known double-locking anti-pattern because underlying * storage gives close enough answer to real one here; and we are * more concerned with flooding than starvation. */ synchronized (lock) { if (size() >= MAX_ENTRIES) { clear(); } } } result = input.intern(); put(result, result); return result; } }
public String intern(String input) { String result = get(input); if (result != null) { return result; } /* 18-Sep-2013, tatu: We used to use LinkedHashMap, which has simple LRU * method. No such functionality exists with CHM; and let's use simplest * possible limitation: just clear all contents. This because otherwise * we are simply likely to keep on clearing same, commonly used entries. */ if (size() >= MAX_ENTRIES) { /* Not incorrect wrt well-known double-locking anti-pattern because underlying * storage gives close enough answer to real one here; and we are * more concerned with flooding than starvation. */ synchronized (lock) { if (size() >= MAX_ENTRIES) { clear(); } } } result = input.intern(); put(result, result); return result; } }
public String intern(String input) { String result = get(input); if (result != null) { return result; } /* 18-Sep-2013, tatu: We used to use LinkedHashMap, which has simple LRU * method. No such functionality exists with CHM; and let's use simplest * possible limitation: just clear all contents. This because otherwise * we are simply likely to keep on clearing same, commonly used entries. */ if (size() >= MAX_ENTRIES) { /* Not incorrect wrt well-known double-locking anti-pattern because underlying * storage gives close enough answer to real one here; and we are * more concerned with flooding than starvation. */ synchronized (lock) { if (size() >= MAX_ENTRIES) { clear(); } } } result = input.intern(); put(result, result); return result; } }
public String intern(String input) { String result = get(input); if (result != null) { return result; } /* 18-Sep-2013, tatu: We used to use LinkedHashMap, which has simple LRU * method. No such functionality exists with CHM; and let's use simplest * possible limitation: just clear all contents. This because otherwise * we are simply likely to keep on clearing same, commonly used entries. */ if (size() >= MAX_ENTRIES) { /* Not incorrect wrt well-known double-locking anti-pattern because underlying * storage gives close enough answer to real one here; and we are * more concerned with flooding than starvation. */ synchronized (lock) { if (size() >= MAX_ENTRIES) { clear(); } } } result = input.intern(); put(result, result); return result; } }