How would you implement a Listener that is queuing events that are executed at the end of thread execution in multithreading environment? The desired behavior would be that each thread has its own queue for events so that they wouldn't mix up and be atomically executed.. So that if thread A calls listener.execute() then only "his" events get executed.
The only way I can think of is using ThreadLocal variable but if I consider the complications here I'd rather not use any.
Let say you have a Tree and you want to remove x nodes, then you don't want to execute refresh x times after each "refresh" event, but you better want to queue them and execute at the end...that spares x-1 refreshes :-)