I need lock a function from another function in java. In example above, I call slave function to print counter. And I need when that if master function called, all threads which calls slave function must be wait master functions to be ended.
How can I do that?
int counter = 0;
private void slave()
{
System.out.println(counter);
}
private void master()
{
lockSlave();
counter ++;
unlockSlave();
}
AtomicIntegerorLongAdder