I would like to find out if there is an extra sigificant overhead of grabbing the same lock more than once. e.g. void fooA() { synchronized (m_lock) { ... } }
void fooB() { synchronized (m_lock) { fooA(); } } When I call fooB(), the flow would grab m_lock twice. I feel this is a design tradeoff. I could have removed the synchronized() in fooA if I am 100% sure fooB is the only place calling it, but to be clean, fooA() should not rely on anything outside its scope if it needs some serialization inside its own logic. Any advise or common practices?
Billybob Marshall
Ranch Hand
Joined: Jan 27, 2004
Posts: 202
posted
0
If fooA is private, I'd probably remove the sync from within it. But either way, I'd say there's no "significant" overhead or performance penalty for locking it twice. In reality, you'll only ending up with one lock, not two anyway.