Questions tagged [reentrantlock]

ReentrantLock is a Java mutex class.

A 'reentrant lock' is a lock that can be re-acquired by the current owner without blocking or deadlock. Java provides an implementation.

230 questions
1
vote
1 answer

Java - ReentrantLock, lock could not be unlocked

Below is the all the information before the thread is locked and after the thread is unlocked. I m using the method lock() and unlock() the ReentrantLock. However, although some process has unlocked the lock, another process could not lock the same…
Vimlan.G
  • 193
  • 1
  • 13
1
vote
1 answer

Restricting access to shared data with re-entrant lock in java

I have a simple requirement where a resource (let's say a linked-list) is shared between two services:one adds elements to it and another one calculates statistics of it. I want to use re-entrant locks in java. I have come up with following…
Arun Rahul
  • 565
  • 1
  • 7
  • 24
1
vote
1 answer

Java ReentrantLock and Condition | producers finish work, consumer gets stuck

General Information: Three reader-threads read randomly from a file in chunks where each chunk has an ID and they write to a normal ArrayList. A writer-thread writes to an outputfile as soon as a chunk with the needed ID is added to the list. For…
SklogW
  • 839
  • 9
  • 22
1
vote
2 answers

ReentrantLock doesn't work out

I can't figure out why the code doesn't work properly. The problem is that ReentrantLock doesn't lock methods invocation in ThreadClass.run() Resource-class which methods are assumed to be locked in ThreadClass public class ResourceClass { …
aime
  • 247
  • 4
  • 16
1
vote
2 answers

Nested monitor in Java

If I'm using a ReentrantLock in Java... When a thread has the lock of an object and it tries to acquire another lock of a different object, does it release the first one or does it still hold it?
1
vote
1 answer

When to use fairness mode in Java concurrency?

I am really confused why this feature need by java. Please share some real examples when fairness mode can be used with ex: ReentrantLock, ReadWriteLock, Semaphore.
fashuser
  • 2,152
  • 3
  • 29
  • 51
1
vote
1 answer

Second thread executed even though first thread locked using ReentrantLock

I am newbie in Java , trying to learn Java concepts with Implementation. The reason for ReentrantLock class here is to understand Locks. I am spawning 3 threads , and in these I just increment a Global Counter. I am protecting the Counter overwrites…
1
vote
1 answer

Ordered write to the same file with ExecutorService

I'm trying to instantiate tasks in a ExecutorService that need to write to file in order,so if there exist 33 tasks they need to write in order... I've tried to use LinkedBlockingQueue and ReentrantLock to guarantee the order but by what I'm…
RomuloPBenedetti
  • 163
  • 2
  • 12
1
vote
1 answer

How to wait for specified time in critical section locked by ReentrantLock?

I need to stop thread somehow for 1 sec while thread is in critical section locked by ReentrantLock. My code is : public class Lock implements Runnable { private ReentrantLock lock = new ReentrantLock(); @Override public void run() { …
Volodymyr Levytskyi
  • 3,364
  • 9
  • 46
  • 83
1
vote
4 answers

How to avoid reads before initialization of all the three maps are done using RentrantLock and return updated set of maps after update is done?

I am trying to implement lock by which I want to avoid reads from happening whenever I am doing a write on my three maps. So my requirement is - Reads block until all three maps have been set for the first time. Now second time, If I am updating…
john
  • 11,311
  • 40
  • 131
  • 251
1
vote
2 answers

ReentrantReadWriteLock limit

Is there a limit to the ReentrantReadWriteLock? I'm now testing my application and it seems my write lock isn't giving out locks anymore (returning true: tryLock()) when I'm at 20 threads.
Martijn
  • 2,268
  • 3
  • 25
  • 51
1
vote
0 answers

Using a ReentrantReadWriteLock within another ReentrantReadWriteLock

I am not sure if I have implemented ReentrantReadWriteLock correctly so I would appreciate if you can let me know if I had done anything wrong. Scenario: Imagine that there are two steps required to make a shirt. The shirts will all be…
1
vote
0 answers

Interleaved ReentrantLocks (for 3D camera movement, LWJGL)

My question is if is rather a valid choice to interleave multiple ReentrantLocks or not for a specific case: camera movement in 3D space (LWJGL, openGL) - with graphical representation of course. My camera controller object holds a private method to…
Florian R. Klein
  • 1,375
  • 2
  • 15
  • 32
1
vote
1 answer

ReentrantLock shared by threads not seeming to honor lock

I have a single ReentrantLock object that I share among threads, but I'm able to lock the same object by different threads. This doesn't seem right as they are different threads. Here is the truncated/simplified output: 11:04:47,136…
user3133269
  • 31
  • 1
  • 4
1
vote
1 answer

Prioritzing acquisition of a fair ReentrantLock where it could potentially be locked

I have a ReentrantLock that a bunch of operations are locking on, that was created as fair with new ReentrantLock(true). Is there a way for a thread to "barge in" onto the lock and acquire it after it's released but before any other threads? I have…
nanofarad
  • 40,330
  • 4
  • 86
  • 117