Concurrency mechanic for a particular situation
The situation is this one (look below EDIT2):
SITUATION
I have a method (method A) that will cycle trught components one by one
and remove them if they meet a criteria which will will trigger the event
(my little method chain reaction) that the question above is dealing with.
I have an AtomicBoolean which will be true while that chain is executing
and will turn false when it's done or not executing, which method A can
access.
Now, I know where exactly method A would trigger the event (it would
trigger it when removing objects), so I can set the AtomicBoolean to true
manually from method A.
Now all I need to do is PAUSE the method untill AtomicBoolean turns false.
I can't use PropertyChangeListener because I can plop it in the middle of
method and use it to pause it, I'd have to break up my method to smaller
ones, which I cannot do,
If Lock class is something that could work here, I'm failling to see how.
Basically, what I need this:
while (AtomicBoolean)
{
Thread.sleep(0);
}
but written in a smarter form, so it wouldn't torture the processor.
No comments:
Post a Comment