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:
jiachun.fjc 2017-05-04 11:36:34 +08:00 committed by Norman Maurer
parent f65885fc54
commit 963cd22a05

View File

@ -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);