Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
// Example of the executor service
class UserRepository implements Closeable {
private FileStore fileStore;
private ConcurrentHashMap<UUID, User> cache = new ConcurrentHashMap<>();
private ReadWriteLock lock = new ReentrantReadWriteLock();
private ExecutorService executors = Executors.newFixedThreadPool(2);
UserRepository(FileStore fnileStore) {
this.fileStore = fileStore;
public CompletableFuture<Void> saveUser(User user) {
return CompletableFuture.runAsync(() -> {
fileStore.write(user.getId(), user);
cache.put(user.getId(), user);
}, executors);
public void close() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment