PPT Slide
class SharedCounter {
private Lock lock = new Lock();
public int increment() {
synchronized (lock) {
local_counter++;
return local_counter;
}
}…
Now erroneous or malicious other class cannot lock out calls to increment. The lock is private. With synchronized method the lock is lockable by anyone that can see the object.
Previous slide
Next slide
Back to first slide
View graphic version