Hi,
I have a Util class with a static method
process which will accept a tree data structure (Composite
Pattern). The problem is I want to prevent the possibility of a StackOveflow if the user of this method is stupid enough to introduce loops within the tree.
What I want to do is to keep a list of nodes which I have already visited. So during the navigation down the tree, I will add the visited nodes to this list.
I want to use a ThreadLocal variable to keep the list of visited nodes.
The issue here is that the variable has to be declared static.
I don't understand the semantics of
static ThreadLocal variable.
Will different threads that call the
process method be using the
same ThreadLocal variable ? Are there any huge design flaws ? Thanks all