* @author Jörg Schaible
*/
public class PoolToyExample {
public static void packageOverviewExample1() {
Pool pool = new Pool(Checksum.class, new Resetter() {
public boolean reset(final Object object) {
((Checksum)object).reset();
return true;
}
});
pool.add(new CRC32());
if (true) {
Checksum checksum = (Checksum)pool.get();
checksum.update("JUnit".getBytes(), 0, 5);
System.out.println("CRC32 checksum of \"JUnit\": " + checksum.getValue());
}
if (true) {
Checksum checksum = (Checksum)pool.get();
if (checksum == null) {
System.out.println("No checksum available, force gc ...");
System.gc();
}
checksum = (Checksum)pool.get();
System.out.println("CRC32 of an resetted checksum: " + checksum.getValue());
((Poolable)checksum).returnInstanceToPool();
}
}