Thread B reenterlock trylock failed to obtain A lock, I hope I can receive B threads directly wait for best, A thread is the announcement that releases the lock to read cache
This code for how to write?
CodePudding user response:
Thread B reenterlock directly. The lock that he will block until A thread reenterlock releaseCodePudding user response:
Public class A (Thread B
The public A (Thread B) {
This. B=B;
}
The run () {
{if (lock. TryLock ())
Sytem. Out. Println (" business ");
LockSouport. UnPark this. (B)
} the finally {
lock.unlock();
}
}
Public class B (
The run () {
LockSouport. Park ();
{if (lock. TryLock ())
Sytem. Out. Println (" business ");
} the finally {
lock.unlock();
}
}
CodePudding user response: