-
Notifications
You must be signed in to change notification settings - Fork 531
Expand file tree
/
Copy pathJsonIteratorPool.java
More file actions
34 lines (30 loc) · 912 Bytes
/
JsonIteratorPool.java
File metadata and controls
34 lines (30 loc) · 912 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
package com.jsoniter;
public class JsonIteratorPool {
private static ThreadLocal<JsonIterator> slot1 = new ThreadLocal<JsonIterator>();
private static ThreadLocal<JsonIterator> slot2 = new ThreadLocal<JsonIterator>();
public static JsonIterator borrowJsonIterator() {
JsonIterator iter = slot1.get();
if (iter != null) {
slot1.set(null);
return iter;
}
iter = slot2.get();
if (iter != null) {
slot2.set(null);
return iter;
}
iter = JsonIterator.parse(new byte[512], 0, 0);
return iter;
}
public static void returnJsonIterator(JsonIterator iter) {
iter.configCache = null;
if (slot1.get() == null) {
slot1.set(iter);
return;
}
if (slot2.get() == null) {
slot2.set(iter);
return;
}
}
}