reentrantlock Questions

1

I am trying to write a test, in which I want to demonstrate the difference between fair and unfair Reentrant locks. The test uses ThreadPoolExecutor and consists of multiple iterations, each of whi...
Perique asked 13/7, 2023 at 15:1

5

Solved

What do you actually use for this method lockInterruptibly? I have read the API however it's not very clear to me. Could anybody express it in other words?
Audraaudras asked 23/7, 2013 at 13:26

1

Solved

The way Lock interface with class Reentrant(true) lock works is that it uses BlockingQueue to store Threads that want to acquire the lock. In that way thread that 'came first, go out first'-FIFO. A...
Corky asked 15/8, 2020 at 21:54

8

Solved

I'm trying to understand what makes the lock in concurrency so important if one can use synchronized (this). In the dummy code below, I can do either: synchronized the entire method or synchroniz...

5

Solved

I have a LockManager that manages the locks of several threads. Sometimes the threads are bad boys, and I have to kill them and ask the LockManager to release all their locks. However, since I use ...
Karajan asked 10/5, 2013 at 21:50

2

As we know, ReentrantLock has a max reentrant limit: Integer.MAX_VALUE; Does synchronized block have reentrant limit too? Update: I found it is hard to write test code for synchronized reentrant: ...
Imperturbation asked 27/2, 2019 at 3:41

3

Solved

I have a main thread and a worker thread. The main thread adds tasks into a queue and the worker thread takes them to compute data. Before I put the objects into the queue I call lock on a Reentran...
Pronunciation asked 15/4, 2016 at 16:26

2

I've stumbled upon this thread some time ago: Does making a reentrant lock static and make it a mutex? and I have an additional question on my own: Im interested if creating a private static final...
Dawdle asked 8/12, 2017 at 21:12

3

Solved

I have taken the following points from this API and I would like to know the difference between the 2 following points: Waiting threads are signalled in FIFO order. The ordering of lock reacq...
Probation asked 23/7, 2013 at 14:49

2

Solved

I am trying to figure out how can we correctly wait until a lock is released in another thread. I think the code will explain better what do I mean: myLock.lock(); sendSomewhereMyLock(myLock); //...
Jeer asked 16/8, 2017 at 20:48

1

I don't understand the difference between them. I thought a lock from the lock interface was reentrant too then what's the difference between them? When would you use each?

1

Solved

ReadWriteLock downgrade is allowed by ReentrantReadWriteLock implementation (tryLock() from the example below always returns true): void downgrade(final ReadWriteLock readWriteLock) { boolean dow...
Phago asked 26/10, 2015 at 9:43

3

Solved

From this link, I understand "Since the lock() and unlock() method calls are explicit, we can move them anywhere, establishing any lock scope, from a single line of code to a scope that spans multi...
Lahdidah asked 14/7, 2015 at 11:27

6

Solved

I came across the example below of a Java class which was claimed to be thread-safe. Could anyone please explain how it could be thread-safe? I can clearly see that the last method in the class is ...
Swelling asked 10/7, 2015 at 14:58

0

I'm using ReentrantLock with its recommended practise (lock, then actual code in try-block, then unlock in finally, see code example below). Sometimes (very very rare) I'm having java.lang.IllegalM...
Ashy asked 25/8, 2014 at 8:48

1

Solved

I have an objective-c class with some methods, which use a GCD queue to ensure that concurrent accesses to a resource take place serially (standard way to do this). Some of these methods need to c...
Eocene asked 21/10, 2013 at 12:12

2

Solved

We are using Spring Web Flow (2.0.9) in the Weblogic 10 clustured environment. And in production we are getting a lot of LockTimeoutException : Unable to acquire conversation lock after 30 seconds....
Tocsin asked 2/3, 2012 at 13:4

4

Solved

I know if using ReentrantLock, it allows the same thread to acquire the same lock more than once. Internally, it has a counter to count the number of the lock acquisition. If you acquired the...
Zimmer asked 3/9, 2013 at 15:30

3

When I run the example class at http://javarevisited.blogspot.in/2013/03/reentrantlock-example-in-java-synchronized-difference-vs-lock.html, I'm seeing the same behavior as with synchronized.
Andante asked 28/8, 2013 at 18:22

3

I am reading about Condition in java.util.concurrent.locks.Condition . Condition factors out the Object monitor methods (wait, notify and notifyAll) >into distinct objects to give the effect of ...

2

Solved

The following is the typical reader and writer pattern (a lot of reads and few writes) private ReadWriteLock lock = new ReentrantReadWriteLock(); private int value; public void writeValue(int ...

1

Solved

In java JRE I saw the code private final ReentrantLock lock; public E poll() { final ReentrantLock lock = this.lock; lock.lock(); Why is lock captured to a private variable? I would expect sim...
Shimmy asked 16/4, 2012 at 19:49

2

Solved

In Brian Goetz's book, Java Concurrency in Practice, his example of a Reentrant lock is programmed like this: Lock lock = new ReentrantLock(); However, I am curious to know if changing the above...
Saltation asked 15/4, 2011 at 15:8

2

Solved

The code below allows us to run a job while ensuring that only one job at a time can run by using ReentrantLock. Is there any way to modify this code to run job.call() asynchronously and to return...
Andrey asked 21/2, 2011 at 17:28
1

© 2022 - 2024 — McMap. All rights reserved.