Package com.esotericsoftware.kryo.pool
Interface KryoPool
-
- All Known Implementing Classes:
KryoPoolQueueImpl
public interface KryoPoolA simple pool interface forKryoinstances. Use theKryoPool.Builderto 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); } });
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classKryoPool.BuilderBuilder for aKryoPoolinstance, constructs aKryoPoolQueueImplinstance.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Kryoborrow()Takes aKryoinstance from the pool or creates a new one (using the factory) if the pool is empty.voidrelease(Kryo kryo)Returns the givenKryoinstance to the pool.<T> Trun(KryoCallback<T> callback)Runs the providedKryoCallbackwith aKryoinstance from the pool (borrow/release aroundKryoCallback.execute(Kryo)).
-
-
-
Method Detail
-
borrow
Kryo borrow()
Takes aKryoinstance from the pool or creates a new one (using the factory) if the pool is empty.
-
run
<T> T run(KryoCallback<T> callback)
Runs the providedKryoCallbackwith aKryoinstance from the pool (borrow/release aroundKryoCallback.execute(Kryo)).
-
-