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? 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. Regards, Jeroen