Replace synchronized with atomic+while loop in case of a method called at a very low rate

I have two functions which must run in a critical section:

public synchronized void f1() { ... }

public synchronized void f2() { ... }

The behavior in my application is as following:

f1 is almost never called. Actually, under normal conditions, this method is never called. If f1 is called anyway, it should return quickly.

f2 is called at a very high rate. It returns very quickly.

These methods never call each other and there is no reentrancy as well.

So when f2 is called, we have some overhead to acquire the lock, which is granted...

Read More »

By: StackOverFlow - Wednesday, 7 November

Related Posts