|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |
See:
Description
Interface Summary | |
---|---|
Poolable | An interface automatically implemented by the proxy instances returned from an Pool . |
Class Summary | |
---|---|
Pool<T> | A simple pool implementation that collects its unused components of a specific type automatically. |
Pool.PoolBuild<T> | |
Pool.PoolingInvoker<T> | The Invoker of the proxy. |
Pool.PoolModeOrBuild<T> | |
Pool.PoolResettedBy<T> | |
Pool.PoolWith<T> |
Enum Summary | |
---|---|
SerializationMode | The mode of serialization for pools. |
A toy to create object pools based on proxies.
The package provides a basic object pool based on proxies, that
enable the return of their pooled object into the pool, when the proxy
gets out of scope and it is garbage collected. Main component is the
Pool toy that manages the
objects of a single pool. Any object retrieved from the pool is wrapped
by such a pool proxy. The proxy also implements Poolable
, that can be used to return
the object manually.
In the following example demonstrates the usage of the pool. The pooled object is once returned by the garbage collector and one time manually. See also the automated reset of the element's status:
Resetter<Checksum>() { public boolean reset(Checksum object) { object.reset(); return true; } }; Pool<Checksum> pool = Pool.create(Checksum.class).resettedBy(resetter).build(new CglibProxyFactory()); pool.add(new CRC32()); { Checksum checksum = pool.get(); checksum.update("JUnit".getBytes(), 0, 5); System.out.println("CRC32 checksum of \"JUnit\": " + checksum.getValue()); } { Checksum checksum = pool.get(); if (checksum == null) { System.out.println("No checksum available, force gc ..."); System.gc(); } checksum = pool.get(); System.out.println("CRC32 of an resetted checksum: " + checksum.getValue()); Poolable.class.cast(checksum).returnInstanceToPool(); }
|
||||||||||
PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES |