import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
class Writer extends Producer implements Runnable {
public void run() {
synchronized (Shared.cache) {
int[] referenceToValue = Shared.cache.get("key");
for (int i = 0; i < referenceToValue.length; i++) {
// Update value in-place; sum will add up to length
referenceToValue[i] = produce();
}
}
}
}
class Reader extends Consumer implements Runnable {
public void run() {
synchronized (Shared.cache) {
consume(Shared.cache.get("key"));
}
}
}
// {