public class BuilderHolder extends ThreadLocalSoft<StringBuilder>
Using ThreadLocal internally, there are leak pitfalls, you must use one of the following modes. (1) static, the only Ref in JVM, to avoid creating temporary Ref multiple times. (2) use try-finally-close mode to remove the Ref.
| Constructor and Description |
|---|
BuilderHolder() |
BuilderHolder(int min,
int max)
init holder, cache the builder only if its less than the max size
|
BuilderHolder(int min,
int max,
ThreadLocal<SoftReference<StringBuilder>> threadLocal) |
| Modifier and Type | Method and Description |
|---|---|
boolean |
anewValue(@NotNull StringBuilder bd)
Reset to current value in a single thread and decide whether it is available
|
@NotNull StringBuilder |
initValue()
Init in a single thread, first time or anewValue() call
|
close, usepublic BuilderHolder()
throws ThreadLocalAttention
ThreadLocalAttentionpublic BuilderHolder(int min,
int max)
throws ThreadLocalAttention
min - init sizemax - max sizeThreadLocalAttentionpublic BuilderHolder(int min,
int max,
ThreadLocal<SoftReference<StringBuilder>> threadLocal)
throws ThreadLocalAttention
ThreadLocalAttention@NotNull public @NotNull StringBuilder initValue()
ThreadLocalSoftinitValue in class ThreadLocalSoft<StringBuilder>public boolean anewValue(@NotNull
@NotNull StringBuilder bd)
ThreadLocalSoftanewValue in class ThreadLocalSoft<StringBuilder>bd - current valueCopyright © 2023. All rights reserved.