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

Recursive Synchronization vs Recursive Reentrant Lock

I know thread is allowed to acquire a monitor owned by itself i.e. In Java, synchronized locks are reentrant as shown in example below. My query is if i use java.util.concurrent.locks.ReentrantLock API it will produce the same result or not, Can we…
T-Bag
  • 10,916
  • 3
  • 54
  • 118
0
votes
1 answer

How implementation of Re-entrant lock and Synchronization is different

As per java source code ReentrantLock's lock(non-fair) is as below. public boolean lock(){ int c=getState(); if(c==0){ compareAndSetState(0,1); } } //getState method public int getState(){ return state; } public…
Nishat
  • 881
  • 1
  • 17
  • 30
0
votes
3 answers

syncronization with nested lock

Sometime, I find in some Java code, they use nested lock to accomplish the syncronization method. code as below // lock for appending state management final Lock appendLock = new ReentrantLock(); // global lock for array read and write…
lawrence
  • 353
  • 2
  • 17
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

Producer Consumer using ReentrantLock and Queue

To understand how multi threading works I am using Queue and ReentrantLock to simulate Producer and Consumer problem. My Producer thread is adding data into the queue but Consumer is not removing. I am not sure if I have implemented it…
crazyStart
  • 127
  • 1
  • 10
0
votes
1 answer

Android Service and worker thread ReentrantLock infinite loop

Hi I want to get rid of an infinite loop which holds a worker thread in a service. I try to use the ReentrantLock() methods but I can't seem to get it to work. My worker thread calls from JNI the nativeWaitForTask method and goes to sleep. But my…
0
votes
1 answer

Issue with Producer-Consumer using Lock and Condition

I have implemented Producer-Consumer program using ReentrantLock and Condition. My implementation runs without any error if I start the Producer thread first. But if I start the Consumer thread first I get a IllegalMonitorStateException. Please…
0
votes
0 answers

Java Locks/Condition Variable - signal() not waking up the thread

so been stuck here, tried to look for answers, couldn't find any. Simply, I keep trying to get the Train to signal to the Passenger that its in the station. Signal keeps looping but passenger just never wakes up. I printed out the hashcode before…
0
votes
1 answer

Does ReentrantLock use Decorator Design Pattern in java?

ReentrantLock contains an abstract class Sync, and Sync has two subclasses FairSync and NonFairSync. I want to know is this Decorator Design Pattern? BTW, is there any good resources about Design Pattern usage in java source code?
expoter
  • 1,622
  • 17
  • 34
0
votes
4 answers

why java ReentrantLock not throw InterruptedException?

I want to create race condition in Java thread Concurrency and create deadlock. I use ReentrantLock, but it doesn't throw InterruptedException. It is deadlock now, and I use lockInterruptibly, but it doesn't throw InterruptedException, can any body…
jsohpill
  • 51
  • 1
  • 6
0
votes
0 answers

ReentrantLock not waiting for lock release

Why after acquiring lock control is going to second lock.lock() statement? Isin't it should wait indefinitely over 2nd lock statement for acquiring it? Is it because I am acquiring lock in single thread? Class LockTest{ private static…
sourcecode
  • 1,802
  • 2
  • 15
  • 17
0
votes
1 answer

Reentrantlock works fine in Java but causes IllegalMonitorException in Scala

I would like to migrate a Java function protected static final Lock LOCK = new ReentrantLock(); public double calculate(...){ try { LOCK.tryLock(20, TimeUnit.SECONDS); ... }finally{ LOCK.unlock() } } The same…
wurmi
  • 333
  • 5
  • 18
0
votes
0 answers

Why ConcurrentHashMap use 'synchronized' inside computeIfAbsent

Inside 'computeIfAbsent' method of ConcurrentHashMap there is code: synchronized (r) { if (casTabAt(tab, i, null, r)) { ... Why not 'ReentrantLock' ?
littleAlien
  • 721
  • 2
  • 8
  • 20
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
1 answer

Running Threads on a File Method

Hi am try to run a thread on my "threadedSort", but i can not use the traditional void run method because it returns void. I also tried using the synchronised method but i don't think it made any difference...same with the reentrant method, i don't…
Arthur Decker
  • 1,191
  • 3
  • 15
  • 45