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

Why am i not able to use the getOwner() method of Reentrant class in subclass directly?

Im trying to use the getOwner method in the class that subclass the ReentractLock class, I know outside the package, protected methods will be available to the subclass only. So i expect the getOwner method to be available to my sublcass MyLock. But…
Arasn
  • 138
  • 10
0
votes
2 answers

SharedArray Deadlock and raise Conditions

I'm trying to stimulate the scenario of deadlocks in the shared array using Reentrant Locks. class SharedArray { private int ff[]; private Lock keys[]; public SharedArray(int n){ ff = new int[n]; keys = new…
Hassaan
  • 3,931
  • 11
  • 34
  • 67
0
votes
1 answer

Reentrant Read Write lock on particular value

My application gets lot of incoming HTTP request. In header of each request, there's a key value pair. Say Header1=App1 The value App1 keeps on changing. So next it can be App2,App3 and like that . However these values can keep on coming in…
AngelsandDemons
  • 2,823
  • 13
  • 47
  • 70
0
votes
2 answers

Deadlock on ReentrantLock in interceptor

I have next problem. When my token is expired I try to refresh it. If this refresh code called by single-thread it works fine, but if there are two or more threads sometimes I catch deadlock. This is my code in Interceptor: private val lock =…
Artem
  • 4,569
  • 12
  • 44
  • 86
0
votes
1 answer

Lock not released even after thread terminates

In the following program, somehow the program doesn't end. When i debugged, during inspecting the lock variable was showing that the lock was being held by the Producer thread as follows java.util.concurrent.locks.ReentrantLock@55584367[Locked by…
Adithya
  • 2,923
  • 5
  • 33
  • 47
0
votes
1 answer

Java 8 - ReentrantLock/Locking an object

I'm wondering if using a ReentrantLock is the solution for my problem; I'm trying to "lock"(prevent other threads from accessing/using it) an object until a certain operation is complete, and then unlock it so other threads can access it. I thought…
0
votes
0 answers

Implement threadsafe service with locks on a per-key basis

My goal is to implement a service which operates on Widgets, which have a property name. That service's operations consist of multiple smaller steps, which should be executed synchronously per name, meaning no two operations on widgets of the same…
Felk
  • 7,720
  • 2
  • 35
  • 65
0
votes
1 answer

How does ReentrantLock.tryLock() works as it seems from source code that it does not use synchronized block or function

As I was using tryLock() method in one of my project, while using the same the question which is striking mind is that - tryLock() is said to be non blocking mechanism, how does it manages to get a lock without blocking. There can be two…
Dibyendu
  • 335
  • 2
  • 7
0
votes
1 answer

How to make long waiting thread to run

I am working in core java. I have one small program which will print numbers 1,2,3 by corresponding threads thread1 , thread2 and thread3. while(true) { synchronized (obj) { System.out.println("Thread…
0
votes
2 answers

ReentrantLock is not showing expected result

Where is the problem? ReentrantLock is not showing expected result. Two threads are executing same time rather than waiting one thread. class MyThread2 extends Thread{ String name; ReentrantLock reentrantLock = new ReentrantLock(); …
emon
  • 1,629
  • 1
  • 17
  • 18
0
votes
1 answer

ReentrantLock's trylock method not allowing turn taking of multiple threads

I was studying MultiThreading concepts. I came across ReentrantLock. It has methods lock and trylock. As I studied them further, I understood that they can be used instead of synchronized keyword block or method. So I tried them again with classic…
JPG
  • 1,247
  • 5
  • 31
  • 64
0
votes
1 answer

Reentrant Lock , busy waiting resolved by the new tryLock method

I was going through java doc description of lockInterruptibly method in ReentrantLock class. My intention was to see if the threads waiting to acquire lock are getting interrupted, may be I am doing it horribly wrong. I know there is an explicit way…
0
votes
0 answers

How can one make a routine, which uses global variables and blocks on a semaphore, a re-entrant routine?

The routine uses global variables The routine blocks on a semaphore, sleep The routine should be re entrant.
0
votes
1 answer

ReentrantLock tryLock()

This is the source code of ReentrantLock#tryLock: public boolean tryLock() { return sync.nonfairTryAcquire(1); } My question is that: There are two types of Synchronizers: FairSync and NonFairSync in the ReentrantLock. Why only the…
jimwi
  • 33
  • 3
0
votes
2 answers

Confused java ThreadPool and ReentrantLock

I get a fixed number of two threads, then submitted 100 tasks, inside which I used a lock and intentionally leave it unlocked, running result of this code is sorted number from 1 to 99, this makes me confused: 1) Is it because the thread is reused…
鄭无爲
  • 53
  • 1
  • 10