Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

Reader-Writer Locks - Part I

Here's an example where we produce a dummy value to write to each element of the cached array so that its sum is either 0 (initial value) or its length (after any complete write operation):

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
class Simulator {
static void simulateWork() {
try {
Thread.sleep(3); // simulates work being done
} catch (InterruptedException ex) {
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content