// Note: This does have the values problem (complicated values can cause memory leaks) sclass BetterThreadLocal { Map map = newWeakHashMap(); bool isSet() { ret map.containsKey(currentThread()); } A get() { ret map.get(currentThread()); } A get(Thread thread) { ret map.get(thread); } void set(A a) { mapPutOrRemove(map, currentThread(), a); } }