Questions tagged [reentrantreadwritelock]

ReentrantReadWriteLock is a Java class providing the lock for working with multiple threads.

ReentrantReadWriteLock is a Java class providing the lock for working with multiple threads.

This lock assumes that some resource can be unlocked (ready to lock before working with it), locked read only (multiple threads can access but none can modify) or locked read/write (only one thread can access and modify). Locks are claimed by calling methods on the lock object. If locks cannot be granted immediately, these calls suspend the current thread. Write lock can be downgraded to the read lock (but not in reverse).

To be sure the resource will not stay permanently locked because of exception, the lock in normally released inside the finally construct.

82 questions
0
votes
1 answer

ReentrantReadWriteLock hang when used within ConcurrentHashMap::compute()

TL;DR - In my application many threads grab a ReentrantReadWriteLock in READ mode while they are inserting entries into a ConcurrentHashMap via the compute() method, and release the READ lock once the lamdba passed to compute() has finished. There's…
0
votes
2 answers

Accessing map gives java.util.ConcurrentModificationException although map is updated using ReentrantReadWriteLock

We have a spring boot service that simply provides data from a map. The map is updated regularly, triggered by a scheduler, meaning we build a new intermediate map loading all the data needed and as soon as it is finished we assign it. To overcome…
hecko84
  • 1,224
  • 1
  • 16
  • 29
0
votes
2 answers

Thread blocked forever when waits on lock operation

I'm writing a java implementation for two-phase locking. So, I'm using Reentrant lock (ReadWrite lock). The problem is that when a thread executes the lock.readLock.lock() or lock.writeLock().lock() and the lock is already locked it stuck their…
0
votes
1 answer

ReentrantReadWriteLock blocking me from act on an object?

I have the following object: public class DataStructures { public Map registeredUser; private ReadWriteLock readWriteLock; public DataStructures() { this.registeredUser = new ConcurrentHashMap<>(); …
0
votes
2 answers

Read lock while Writing

I need help in understanding the below code : private Predicate composedPredicate = null; public boolean evaluate(Task taskData) { boolean isReadLock = false; try{ rwl.readLock().lock(); isReadLock = true; …
0
votes
1 answer

How to Synchronize File operation using java? Synchronized or Lock?

I created a application for reading and writing to a remote location property file using JSCH library. I want to synchronize the write operation . This is my code , class WebApp{ private String webappName; private boolean isQA = false; …
0
votes
1 answer

ReadWriteLock writelock saturated

I have an issue with the Writer thread being starved without getting a lock. Please have a look at the following code. If I am trying to get the lock using tryLock() for the read lock, the writer process will become starved and it will never be…
0
votes
1 answer

Fair ReadWriteLock with Conditions

First of all I checked previous questions about this topic, however none fits my specific problem. I got the following Code that illustrates sensors with a timestamp and data stored in a double array, additionally an instance of my implemented…
Greg
  • 49
  • 6
0
votes
3 answers

Using ReentrantReadWriteLock and a boolean flag

I have a cache that gets loaded upfront with a large amount of data (by a background thread) and is unusable until full (it will also get reloaded every so often and be unusable during that load). I want the classes that use it to check a flag…
Gandalf
  • 9,648
  • 8
  • 53
  • 88
0
votes
1 answer

Quasar ReenterantReadWriteLock can't be acquired

I've got a lock: private ReentrantReadWriteLock requestWaitingLock; And I'm executing this block inside a…
0
votes
1 answer

Java ReadWriteLock Reentrance

Hi i have read about the ReadWriteLock in Java but i am not sure that i have grasped the reentrance part of it. Here is two brief code examples using only one main thread to show reentrance public class Locks { public static void main( String[]…
0
votes
0 answers

ReentrantReadWriteLock - Not able to acquire write lock, because of read lock

I'm facing a problem while acquiring write lock and then do some operation using ReentrantReadWriteLock There are two classes say ClassA and ClassB ClassA is holding write lock ClassB is having read lock public static final ReentrantReadWriteLock…
Nitesh Jain
  • 177
  • 2
  • 13
0
votes
1 answer

Is ReentrantReadWriteLock implemented as a spin-lock?

How does ReentrantReadWriteLock work? Is it a spin-lock? The question comes from Elasticsearch, when it shows java.lang.ThreadLocal$ThreadLocalMap.expungeStaleEntry(Unknown Source) java.lang.ThreadLocal$ThreadLocalMap.remove(Unknown Source) …
cybersoft
  • 1,453
  • 13
  • 31
0
votes
3 answers

Using Java ReadWriteLock to synchronise cached data - whether to mark state variables volatile?

The ReadWriteLock javadoc at Oracle and its implementation describe what the lock does and how to use it but doesn't say anything about whether to use the volatile keyword. This is not the same question as…
Adam
  • 5,215
  • 5
  • 51
  • 90
0
votes
1 answer

Thread is not waiting for new data using Condition

I'm trying to program something for a lab that basically is a web cache that stores data in a folder so if a client wants to open a webpage, that page will be stored in the cache folder if it is not already there, and it will be showed to the…