Skip to content

Commit b414e32

Browse files
committed
Use ThreadLocal.withInitial in JsonUtils
1 parent 7ad9bb0 commit b414e32

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

src/main/java/com/github/fabienrenaud/jjb/JsonUtils.java

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.github.fabienrenaud.jjb;
22

3+
import com.dslplatform.json.JsonWriter;
4+
35
import javax.json.spi.JsonProvider;
46
import java.io.ByteArrayOutputStream;
57

@@ -35,25 +37,10 @@ public static com.dslplatform.json.JsonWriter dslJsonWriter() {
3537
return writer;
3638
}
3739

38-
private static final ThreadLocal<ByteArrayOutputStream> THREAD_BYTE_ARRAY_OUTPUT_STREAM = new ThreadLocal<ByteArrayOutputStream>() {
39-
@Override
40-
protected ByteArrayOutputStream initialValue() {
41-
return new ByteArrayOutputStream();
42-
}
43-
};
44-
45-
private static final ThreadLocal<StringBuilder> THREAD_STRING_BUILDER = new ThreadLocal<StringBuilder>() {
46-
@Override
47-
protected StringBuilder initialValue() {
48-
return new StringBuilder();
49-
}
50-
};
51-
52-
private static final ThreadLocal<com.dslplatform.json.JsonWriter> THREAD_DSL_WRITER = new ThreadLocal<com.dslplatform.json.JsonWriter>() {
53-
@Override
54-
protected com.dslplatform.json.JsonWriter initialValue() {
55-
return new com.dslplatform.json.JsonWriter();
56-
}
57-
};
40+
private static final ThreadLocal<ByteArrayOutputStream> THREAD_BYTE_ARRAY_OUTPUT_STREAM = ThreadLocal.withInitial(ByteArrayOutputStream::new);
41+
42+
private static final ThreadLocal<StringBuilder> THREAD_STRING_BUILDER = ThreadLocal.withInitial(StringBuilder::new);
43+
44+
private static final ThreadLocal<com.dslplatform.json.JsonWriter> THREAD_DSL_WRITER = ThreadLocal.withInitial(JsonWriter::new);
5845

5946
}

0 commit comments

Comments
 (0)