I have code similar to following:
class OuterClass
{
private final AtomicInteger count = new AtomicInteger(0);
private class InnerClass extends TimerTask
{
public void run()
{
......
......
incremenetCount();
}
}
public void doSomething()
{
.......
.......
incremenetCount();
}
private void incrementCount()
{
count.incrementAndGet();
}
}
Is calling incrementCount
from inner class the same as calling it from any other function in outer class as the synchronization is actually around the variable count
?