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
0
votes
1 answer

Reentrant lock await and signalAll methods

Why the following very simple code does not work.. it gets stuck.. I am trying to use the explicit lock java.util.concurrent.locks.ReentrantLock; and its newCondition() method. Here is my code: import java.util.concurrent.locks.Condition; …
Rollerball
  • 12,618
  • 23
  • 92
  • 161
0
votes
1 answer

Clarification about the following API ReentranReadWriteLock

Directly from this API: When constructed as fair, threads contend for entry using an approximately arrival-order policy. When the currently held lock is released either the longest-waiting single writer thread will be assigned the write lock,…
Rollerball
  • 12,618
  • 23
  • 92
  • 161
0
votes
0 answers

Lock using ReentrantLock in java

I'm trying to implement at playlist in java. The only problem is that populatePlaylist() is a bit slow and needs to be locked. I have written this code but it doesn't seem to work. private static final Lock lock = new ReentrantLock(); …
Markus
  • 2,526
  • 4
  • 28
  • 35
0
votes
2 answers

Java synchronized statement

I need a threadsafe arraylist like this. public class BookingList { private List bookings; public BookingList() { bookings = Collections.synchronizedList(new ArrayList()); } @Override public void…
Vering
  • 907
  • 9
  • 19
0
votes
1 answer

Java - Reentrant Lock, can't access newly created Condition

I have created a new Condition chopstickFree and in my pickUpChopstick() method, I am waiting for a lock on it but I can't get access to it at all. Through debugging I have found that when it gets to the chopstickFree.await() line in the…
mgibson
  • 6,103
  • 4
  • 34
  • 49
0
votes
2 answers

Why isn't the awaiting thread activated with a signalAll?

I got 2 functions. The first one discoverHosts() sends an request message to other computers. After this it goes to sleep with the await command. A separate threat calls the handleMessage() function when he receives a response. After he handles the…
Dommicentl
  • 721
  • 1
  • 5
  • 12
0
votes
0 answers

Wrapping ExecutorService to provide custom execution

I want to write a reusable piece of code to allow waiting conditions while submitting tasks to an executor service. There are alot of implementaions for neat ways of blocking if too many tasks are queue, e.g. here I need a executor that evaluates…
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
0
votes
1 answer

BroadcastReceiver and ReentrantLock. Are there any problems?

I'm developing a clickable widget. I want to use a static java.util.concurrent.locks ReentrantLock so the widget logic is only called once at a time. But my fear is, that it may be possible in a very rare condition that the lock is not released,…
keiki
  • 3,260
  • 3
  • 30
  • 38
0
votes
2 answers

How does ReentrantLock synchronize?

I have looked at the Java API for ReentrantLock and what I can see is that no synchronization is used with the synchronized keyword. Is it in the below method in AbstractQueuedSynchronizer (that ReentrantLock is refering to when trying to aquire a…
Rox
  • 2,647
  • 15
  • 50
  • 85
-1
votes
1 answer

Never ending read request.! Reentrant Lock

While writing a piece of code for work I have encountered a use case for ReentrantReadWriteLock. So far my understanding is as long as there are more than zero thread with read lock a thread cannot acquire write lock. Application I am working on is…
aman goyal
  • 191
  • 2
  • 14
-1
votes
1 answer

Is Reentrant Lock a Object level lock or Class level lock?

I see in many tutorials for Reentrant lock, they create a new Reentrant lock and resource is injected, lock and unlock of reentrant lock is called in try/finally block. I don't understand the connection between this lock and resource which is used…
-1
votes
1 answer

ReentrantLock Fairness

My ReentrantLock is not working as my expectiation. I expected the result of below code to have two threads locked and unlocked randomly but I got the result was always unlock on one thread. Can anyone explain ReentrantLock and I am trying to…
Wing Kui Tsoi
  • 474
  • 1
  • 6
  • 16
-1
votes
1 answer

How to make sure that multiple threads using multiple objects can access a part of code mutually exclusive

I have a method which can be accessed by one thread at a time. Even if threads use different objects, only one thread should access the method at a time. What can I use in Java do achieve this? I think 'synchronized' keyword will allow multiple…
hars
  • 127
  • 4
  • 17
-1
votes
1 answer

How to comparing the TPS of ReentrantLock and Synchronization

I want to measure the TPS of ReentrantLock and Synchronization.At The same Time I want draw a chart to show the change as the count of thread goes on. But Now,I can not find a satisfied tools to complete it.The result is like this picture: The…
StackNow
  • 29
  • 5
-1
votes
2 answers

What happens if the thread acquires 10 reentrant locks and dies?

Suppose a thread acquires reentrant lock on a resource multiple times and dies. What will happen to the resource? Can another client access the resource?
a3.14_Infinity
  • 5,653
  • 7
  • 42
  • 66
1 2 3
15
16