Jeroen Frijters wrote:
Ian Rogers wrote:
here is the revised patch.

+      int arraySize = group.activeCount();
+      Thread[] threadList = new Thread[arraySize];
+      int filled = group.enumerate(threadList);
+      while (filled == arraySize)
+      {
+        arraySize *= 2;
+        threadList = new Thread[arraySize];
+        filled = group.enumerate(threadList);
+      }

Shouldn't the initial array be arraySize + 1, to avoid always having to 
enumerate twice?

This code is taken from Thread.getAllStackTraces so the problem should effect both.

A bigger problem is that the ThreadLocal can be resurrected after the finalizer 
has run, so you need to either make localIndex in ThreadLocal volatile and set 
it to -1 in the finalizer, or use a PhantomReference and a ReferenceQueue to do 
the clean up.

How can then the thread local be resurrected after the finalizer is run? All the references in ThreadLocal and InheritableThreadLocal are weak and will be atomically cleared prior to the finalizer being run. All other references must be dead for the finalizer to have been run. The finalizer doesn't use the ThreadLocal it just clears all references to the slot it used to reference prior to saying that slot can be reused.

Given that thread locals normally only die when the VM shuts down or by class unloading, its quite tempting just to ignore the situation of reclaiming their storage - its certainly a much smaller problem than the performance of get and set.

Thanks,
Ian

Reply via email to