I'm aware of this similar question, but mine concerns a specific case of ThreadLocal cleanup.
To maintain state on a thread basis I'm storing an (unknown) number of ThreadLocals in a static Vector. Sometimes a "greedy" thread will need more ThreadLocals that are available and as a result the Vector size will be increased. While the cleanup using ThreadLocal.remove() is not a problem in my scenario, I wonder if it will ever be possible to shrink the Vector size after a greedy thread dies or if it is bound to only grow (or at best remain the same).
To clarify: my understanding is that of any given ThreadLocal a different instance will exist for every thread. How could then my static Vector know, when it is accessed from thread A, that the values of ThreadLocal T are empty for all existing threads?
Thanks for your help