Results 1 to 1 of 1
Thread: Demonstrating the WeakHashMap
-
Demonstrating the WeakHashMap
Java Code:import java.util.Map; import java.util.WeakHashMap; public class Weak { public static void main(String args[]) { final Map map = new WeakHashMap(); map.put(new String("Java-Forums"), "www.java-forums.org"); Runnable runner = new Runnable() { public void run() { while (map.containsKey("Java-Forums")) { try { Thread.sleep(500); } catch (InterruptedException ignored) { } System.out.println("Waiting"); System.gc(); } } }; Thread t = new Thread(runner); t.start(); System.out.println("Main waiting"); try { t.join(); } catch (InterruptedException ignored) { } } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks