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
2 answers

ReadWriteRentrantLock

My understanding of the RentrantReadWriteLock is that it allows many reads at the same time but only one write. When we try to acquire a read lock the doc states Acquires the read lock if the write lock is not held by another thread and returns…
More Than Five
  • 9,959
  • 21
  • 77
  • 127
0
votes
3 answers

what happen to the readwritelock if current thread crashes

As title says, curious what happens to the readwritelock when the current thread crash. readlock.lock(); try { ... } finally { readlock.unlock(); } We can definitely unlock in the finally block to prevent any abruption. But what if the…
Alfred
  • 1,709
  • 8
  • 23
  • 38
0
votes
1 answer

Servlet design, concurrent access to field

I have rather general question, please advice. I have a servlet. This servlet has private field. Private field is a kind of metadata stuff (public class Metadata{//bla-bla-bla}). When GET request is processed, this metadata is used to perform some…
0
votes
2 answers

Java ReentrantReadWriteLock requests

Just a quick question about ReadWriteLocks in Java (specifically the ReentrantReadWriteLock implementation) as I don’t find the sun documentation clear. What happens if a read lock is held by a thread when a write lock is requested by another? Does…
Lehane
  • 47,588
  • 14
  • 53
  • 53
0
votes
0 answers

How to find out, if ReentrantReadWriteLock's ReadLock is held before API Level 9

I noticed, that Java's ReentrantReadWriteLock is different in API versions <9 and >=9. Especially important for me, the method getReadHoldCount() isn't available in the older version. Now my question is, how do I detect if a ReadLock is held by the…
Kirill Rakhman
  • 42,195
  • 18
  • 124
  • 148
-1
votes
3 answers

One ReentrantReadWriteLock instance per Variable to be synchronized?

I am going to parallelize some code with some global variables. I am going to use ReentrantReadWriteLock. Did I understand it right, that I need one own instance of ReentrantReadWriteLock per variable I want to make thread safe? I mean, when I have…
Kaspatoo
  • 1,223
  • 2
  • 11
  • 28
-2
votes
1 answer

Is it safe to call unlock() on a lock which might have already been unlocked?

In this example: private ReentrantReadWriteLock mLock = new ReentrantReadWriteLock(); public void method(boolean condition) { try { mLock.writelock.lock() if (condition) { mLock.writelock.unlock(); } }…
Kialandei
  • 394
  • 1
  • 11
1 2 3 4 5
6