K
Karsten Wutzke
Hi all!
Is there a nicer way than nesting synchronized blocks to get locks on
several objects at one time?
I have two threads running, which work pretty much on the same group of
objects, whenever one of them performs a step. I want to implement an
all or nothing strategy, that is, either of the two threads may start to
perform a step *anytime*, but when it starts, changes by the other
thread on these objects should be blocked. So in effect, both can start
anytime, but the one happening earlier shall block the other until its
finished.
I see no other way but to lock all objects the threads will work on up
front. But I think, there's something better - something I'm not
thinking of.
Any help is appreciated on what to do here!
Karsten
Is there a nicer way than nesting synchronized blocks to get locks on
several objects at one time?
I have two threads running, which work pretty much on the same group of
objects, whenever one of them performs a step. I want to implement an
all or nothing strategy, that is, either of the two threads may start to
perform a step *anytime*, but when it starts, changes by the other
thread on these objects should be blocked. So in effect, both can start
anytime, but the one happening earlier shall block the other until its
finished.
I see no other way but to lock all objects the threads will work on up
front. But I think, there's something better - something I'm not
thinking of.
Any help is appreciated on what to do here!
Karsten