All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.jsoniter.JsonIteratorPool Maven / Gradle / Ivy

Go to download

jsoniter (json-iterator) is fast and flexible JSON parser available in Java and Go

There is a newer version: 0.9.23
Show newest version
package com.jsoniter;

public class JsonIteratorPool {

    private static ThreadLocal slot1 = new ThreadLocal();
    private static ThreadLocal slot2 = new ThreadLocal();

    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;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy