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

Is using ReentrantLock reliable as synchronized?

I searched a lot but was confused with the process of 'ReentrantLock' and normal 'synchronized' . For example(1): Object obj = new Object(); synchronized(obj){ //lock is guaranteed to be acquired } example(2) Lock lock = new…
ak500
  • 33
  • 4
0
votes
5 answers

Reetrant locks in java

I am new to Multi Threading in java. I was trying to use locks.Here is my code sample. package com; import java.util.Random; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; import…
0
votes
1 answer

On what object Reentrant lock aquire lock on?

Hello I have question about ReentrantLocks in Concurrent package. //First Object ob = new Object(); synchronized(ob){ } //Second Lock lock = new ReentrantLock(); lock.lock(); try{ } finally{ lock.unlock(); } It says both Pieces of code are…
0
votes
0 answers

Java ReentrantLock issue

Hello I'm having some issues regarding Lock's implementation: ReentrantLock. I'm using a singleton cache inside Spring 3.0(web). However when I open several browser tabs at the exact same time, all threads seem to lock, and I get several unnecesary…
delpo
  • 210
  • 2
  • 18
0
votes
2 answers

Execution of threads in a queue in Java

I have this exercise: Develop a multi-threaded application. Use java.util.concurrent opportunities. DONT USE: synchronized, BlockingQueue, BlockingDeque All entities wishing to access a resource must be threads. Use the opportunities of…
0
votes
1 answer

Benefits of using ReentrantLock over synchronized

I find out one more benefit of using ReentrantLock over synchronized Below code shows even if exception occurs in critical section lock is released(Using ReentrantLock ) void someMethod() { //get the lock before processing critical section. …
0
votes
1 answer

What's the benefit of having two ReentrantLock in a class?

If I have this code: public class PrLock { private Lock lock1= new ReentrantLock(); private Lock lock2= new ReentrantLock(); private int num=0; public void addLock1(){ lock1.lock(); try { num++; …
0
votes
2 answers

Java, Lock, Condition - Signal not waking waiting thread

I have a problem with which i am stuck for some hours and I don't really know how to solve it. It's quite simple - i have some threads, one of them needs to wait for signal from the other one. Somehow, even if I make signal on a condition... nothing…
0
votes
0 answers

Avoiding multiple lock attempts java

I have the following method: public foo bar(String id) { Lock localLock = lockUtil.lock(id); try { do something; return foo; } finally { lock.unlock(); } } I need to override this method to take in another…
user3791554
  • 53
  • 1
  • 4
0
votes
1 answer

Java basic thread pool implementation with locks.ReentrantLock

I'm new at Java. I was just experimenting with threads, and I wanted to create something like a Thread Pool (if this is actually what I am doing..). Basically I have a while loop which fires Threads until there are still tasks to be executed &&…
Redoman
  • 3,059
  • 3
  • 34
  • 62
0
votes
2 answers

Query about disadvantage of Reentrant locks over synchronized block

I am reading comparison between Reentrant locks and synchronization blocks in java. I am going through the various resources on internet. One disadvantage that I discovered using Reentrant locks over synchronization blocks is that in previous one,…
Vinit89
  • 583
  • 1
  • 7
  • 31
0
votes
1 answer

Reentrant Read/Write locks in eclipse have two lock/unlock methods

I noticed that while calling lock/unlock on a ReentrantReadWrite lock, I am prompt with two lock and unlock methods. For example, in the WriteLock I have a Lock() with -75% and another Lock() with no %. Both of these have the same documentations. I…
Quantico
  • 2,398
  • 7
  • 35
  • 59
0
votes
0 answers

FIFO for Write Order in ConcurrentHashMap

My CHM already contains following Data -> 1 Apple 2 Banana 3 Cat 4 dog 1,2,3,4 are keys and Apple, banana... are keys correspondingly. If 3 threads t1, t2, t3 wants to modify the same existing record [3 Cat] . I need this write in FIFO…
0
votes
1 answer

Java - Reentrant WriteLock on static methods

How to use WriteLock on a static method? this is what I have got: m_unitLock = new ReentrantReadWriteLock(); m_unitReadLock = m_unitLock.readLock(); m_unitWriteLock = m_unitLock.writeLock() static List units = new…
tokhi
  • 21,044
  • 23
  • 95
  • 105
0
votes
2 answers

ReentrantLock says "unlocked" but first thread stops

We're calling "lock()" on a ReentrantLock and threads are getting stuck there when they apparently shouldn't. When debugging with a breakpoint just before the call to "lock()", the first thread would stop there with the program pointer going to…
Victor Basso
  • 5,556
  • 5
  • 42
  • 60