Back
Close

Computing with Data

elgeish
158.5K views

Reader-Writer Locks - Part IV

Can we make it run faster? The answer — in this case — is a joyful yes; we modify the program to use a reader-writer lock:

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
class Shared {
static final Map<String, int[]> cache = new HashMap<>();
private static final ReadWriteLock lock = new ReentrantReadWriteLock();
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Create your playground on Tech.io
This playground was created on Tech.io, our hands-on, knowledge-sharing platform for developers.
Go to tech.io
codingame x discord
Join the CodinGame community on Discord to chat about puzzle contributions, challenges, streams, blog articles - all that good stuff!
JOIN US ON DISCORD
Online Participants