mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 06:45:07 +02:00
8278255: Add more warning text in ReentrantLock and ReentrantReadWriteLock
Reviewed-by: prappo, alanb
This commit is contained in:
parent
32c7681cf3
commit
5053b70a7f
3 changed files with 9 additions and 7 deletions
|
@ -80,11 +80,11 @@ import java.util.concurrent.TimeUnit;
|
||||||
*
|
*
|
||||||
* <pre> {@code
|
* <pre> {@code
|
||||||
* Lock l = ...;
|
* Lock l = ...;
|
||||||
* l.lock();
|
* l.lock(); // lock() as the last statement before the try block
|
||||||
* try {
|
* try {
|
||||||
* // access the resource protected by this lock
|
* // access the resource protected by this lock
|
||||||
* } finally {
|
* } finally {
|
||||||
* l.unlock();
|
* l.unlock(); // unlock() as the first statement in the finally block
|
||||||
* }}</pre>
|
* }}</pre>
|
||||||
*
|
*
|
||||||
* When locking and unlocking occur in different scopes, care must be
|
* When locking and unlocking occur in different scopes, care must be
|
||||||
|
|
|
@ -71,8 +71,9 @@ import jdk.internal.vm.annotation.ReservedStackAccess;
|
||||||
* is available even if other threads are waiting.
|
* is available even if other threads are waiting.
|
||||||
*
|
*
|
||||||
* <p>It is recommended practice to <em>always</em> immediately
|
* <p>It is recommended practice to <em>always</em> immediately
|
||||||
* follow a call to {@code lock} with a {@code try} block, most
|
* follow a call to {@code lock} with a {@code try} block, and
|
||||||
* typically in a before/after construction such as:
|
* to <em>always</em> immediately call {@code unlock} as the
|
||||||
|
* first statement in the finally block, as follows:
|
||||||
*
|
*
|
||||||
* <pre> {@code
|
* <pre> {@code
|
||||||
* class X {
|
* class X {
|
||||||
|
@ -80,11 +81,11 @@ import jdk.internal.vm.annotation.ReservedStackAccess;
|
||||||
* // ...
|
* // ...
|
||||||
*
|
*
|
||||||
* public void m() {
|
* public void m() {
|
||||||
* lock.lock(); // block until condition holds
|
* lock.lock(); // lock() as the last statement before the try block
|
||||||
* try {
|
* try {
|
||||||
* // ... method body
|
* // ... method body
|
||||||
* } finally {
|
* } finally {
|
||||||
* lock.unlock();
|
* lock.unlock(); // unlock() as the first statement in the finally block
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
* }}</pre>
|
* }}</pre>
|
||||||
|
|
|
@ -141,6 +141,7 @@ import jdk.internal.vm.annotation.ReservedStackAccess;
|
||||||
*
|
*
|
||||||
* void processCachedData() {
|
* void processCachedData() {
|
||||||
* rwl.readLock().lock();
|
* rwl.readLock().lock();
|
||||||
|
* // Code between the lock() above, and the unlock() below must not throw
|
||||||
* if (!cacheValid) {
|
* if (!cacheValid) {
|
||||||
* // Must release read lock before acquiring write lock
|
* // Must release read lock before acquiring write lock
|
||||||
* rwl.readLock().unlock();
|
* rwl.readLock().unlock();
|
||||||
|
@ -158,7 +159,7 @@ import jdk.internal.vm.annotation.ReservedStackAccess;
|
||||||
* rwl.writeLock().unlock(); // Unlock write, still hold read
|
* rwl.writeLock().unlock(); // Unlock write, still hold read
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
* // Make sure that code that could throw is executed inside the try block
|
||||||
* try {
|
* try {
|
||||||
* use(data);
|
* use(data);
|
||||||
* } finally {
|
* } finally {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue