forked from json-iterator/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonStreamPool.java
More file actions
35 lines (30 loc) · 947 Bytes
/
JsonStreamPool.java
File metadata and controls
35 lines (30 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.jsoniter.output;
public class JsonStreamPool {
private final static ThreadLocal<JsonStream> slot1 = new ThreadLocal<JsonStream>();
private final static ThreadLocal<JsonStream> slot2 = new ThreadLocal<JsonStream>();
public static JsonStream borrowJsonStream() {
JsonStream stream = slot1.get();
if (stream != null) {
slot1.set(null);
return stream;
}
stream = slot2.get();
if (stream != null) {
slot2.set(null);
return stream;
}
return new JsonStream(null, 512);
}
public static void returnJsonStream(JsonStream jsonStream) {
jsonStream.configCache = null;
jsonStream.indention = 0;
if (slot1.get() == null) {
slot1.set(jsonStream);
return;
}
if (slot2.get() == null) {
slot2.set(jsonStream);
return;
}
}
}