I have a VM-wide Singleton. In this singleton I have a variable (or property) that is set by calling threads. I want the following:
1. When a calling
thread sets it, that value is visible only to that calling thread (or rather within the singleton only when called by that thread) and all the sub-threads it spawns
2. Every calling thread (to the singleton's method) gets a separate instance (although all sub-threads of that calling thread are also considered to be of the same thread)
What is the best/most-accurate(?) way to do this?
As a quick example of something like what I'm talking about:
imagine a variable "currentCaller". Let's say this is set by calling MySingleton.setCaller() (this method may or may not be static - any recommendations?) If Thread "A" sets it to "John" then every time Thread "A" or any threads under Thread "A" call any method on MySingleton, it will know to use currentUser=John. At the same time, Thread "B" sets it to "Joe" and it should be Joe for all it's calls.
Thanks!