import java.util.HashMap; class FinalizeTest { public static class Finalizable { private static int total; private String name; public Finalizable(String name) { this.name = name; } public void finalize() { if (name.equals("0")) { total++; System.out.println("finalized " + total); } } } public static void main(String[] args) { HashMap map = new HashMap(); int counter = 0; do { double sine_weight = (Math.sin(counter) + 1.0) / 2.0; int key_counter = (int)(8192 * 65535 * sine_weight); String key = Integer.toString(key_counter); counter++; map.put(key, new Finalizable(key)); if (key.equals("0")) { try { Thread.sleep(10); } catch (InterruptedException ie) { } } } while (true); } }