public interface KryoPool
Kryo instances. Use the KryoPool.Builder to construct a pool instance.
Usage:
import com.esotericsoftware.kryo.Kryo;
import com.esotericsoftware.kryo.pool.*;
KryoFactory factory = new KryoFactory() {
public Kryo create () {
Kryo kryo = new Kryo();
// configure kryo instance, customize settings
return kryo;
}
};
// Simple pool, you might also activate SoftReferences to fight OOMEs.
KryoPool pool = new KryoPool.Builder(factory).build();
Kryo kryo = pool.borrow();
// do s.th. with kryo here, and afterwards release it
pool.release(kryo);
// or use a callback to work with kryo (pool.run borrows+releases for you)
String value = pool.run(new KryoCallback() {
public String execute(Kryo kryo) {
return kryo.readObject(input, String.class);
}
});
| Modifier and Type | Interface and Description |
|---|---|
static class |
KryoPool.Builder
Builder for a
KryoPool instance, constructs a KryoPoolQueueImpl instance. |
| Modifier and Type | Method and Description |
|---|---|
Kryo |
borrow()
Takes a
Kryo instance from the pool or creates a new one (using the factory) if the pool is empty. |
void |
release(Kryo kryo)
Returns the given
Kryo instance to the pool. |
<T> T |
run(KryoCallback<T> callback)
Runs the provided
KryoCallback with a Kryo instance from the pool (borrow/release around
KryoCallback.execute(Kryo)). |
Kryo borrow()
Kryo instance from the pool or creates a new one (using the factory) if the pool is empty.<T> T run(KryoCallback<T> callback)
KryoCallback with a Kryo instance from the pool (borrow/release around
KryoCallback.execute(Kryo)).Copyright © 2023. All rights reserved.