InternalThreadLocalMap#stringBuilder: ensure memory overhead
Motivation: InternalThreadLocalMap#stringBuilder: ensure memory overhead Modification: If the capacity of StringBuilder is greater than 65536 then release it on the next time you get StringBuilder and re-create a StringBuilder. Result: Possible less memory usage.
This commit is contained in:
parent
f65885fc54
commit
963cd22a05
@ -35,6 +35,7 @@ import java.util.WeakHashMap;
|
||||
*/
|
||||
public final class InternalThreadLocalMap extends UnpaddedInternalThreadLocalMap {
|
||||
|
||||
private static final int STRING_BUILDER_MAX_CAPACITY = 1024 << 6;
|
||||
private static final int DEFAULT_ARRAY_LIST_INITIAL_CAPACITY = 8;
|
||||
|
||||
public static final Object UNSET = new Object();
|
||||
@ -164,7 +165,7 @@ public final class InternalThreadLocalMap extends UnpaddedInternalThreadLocalMap
|
||||
|
||||
public StringBuilder stringBuilder() {
|
||||
StringBuilder builder = stringBuilder;
|
||||
if (builder == null) {
|
||||
if (builder == null || builder.capacity() > STRING_BUILDER_MAX_CAPACITY) {
|
||||
stringBuilder = builder = new StringBuilder(512);
|
||||
} else {
|
||||
builder.setLength(0);
|
||||
|
Loading…
Reference in New Issue
Block a user