remove any Reentrant locks in favor of a CAS linked list by andimarek · Pull Request #241 · graphql-java/java-dataloader
This PR removes any usage of Reentrant Lock in DataLoader in favor of using a self made Linked List and updates to it via AtomicReference CAS.
CacheMap change
This is a breaking change for the future cache CacheMap.
In order to avoid any locking
CacheMap<K, V> set(K key, CompletableFuture<V> value);
was replaced with
CompletableFuture<V> setIfAbsent(K key, CompletableFuture<V> value);
which is required to be atomic (like for example offered by ConcurrendHashMap)
This requirement also means that the underlying cache implementation must support this atomic operation.
Concurrent loads without batching, but with caching
Previously it was guaranteed that for one key with caching enabled and batching disabled, the dispatching only happens once.
Now because we avoid any form on lock this is not guaranteed anymore: there could be unnecessary dispatch calls when concurrent load calls are happening.