Imagine a Java class with three methods:
master()
foo()
bar()
I want to synchronize master()
and foo()
and also master()
and bar()
, without synchronizing foo()
and bar()
. It can be done will a separate lock for every pair of synchronized methods, but my actual code has many more than three methods so I was hoping there's a way to do it without so many lock objects.
master
is called,foo
can't be called and whenmaster
is called,bar
can't be called?foo
andbar
can be called at the same time (assumingmaster
isn't called, of course).master()
, or can there be other combinations?foo()
concurrently?