mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8186056: Miscellaneous changes imported from jsr166 CVS 2017-09
Reviewed-by: martin, psandoz
This commit is contained in:
parent
229cce5f44
commit
c3664b7f38
16 changed files with 193 additions and 135 deletions
|
@ -73,7 +73,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* available in the buffer. This can be achieved using two
|
||||
* {@link Condition} instances.
|
||||
* <pre>
|
||||
* class BoundedBuffer {
|
||||
* class BoundedBuffer<E> {
|
||||
* <b>final Lock lock = new ReentrantLock();</b>
|
||||
* final Condition notFull = <b>lock.newCondition(); </b>
|
||||
* final Condition notEmpty = <b>lock.newCondition(); </b>
|
||||
|
@ -81,7 +81,7 @@ import java.util.concurrent.TimeUnit;
|
|||
* final Object[] items = new Object[100];
|
||||
* int putptr, takeptr, count;
|
||||
*
|
||||
* public void put(Object x) throws InterruptedException {
|
||||
* public void put(E x) throws InterruptedException {
|
||||
* <b>lock.lock();
|
||||
* try {</b>
|
||||
* while (count == items.length)
|
||||
|
@ -95,12 +95,12 @@ import java.util.concurrent.TimeUnit;
|
|||
* }</b>
|
||||
* }
|
||||
*
|
||||
* public Object take() throws InterruptedException {
|
||||
* public E take() throws InterruptedException {
|
||||
* <b>lock.lock();
|
||||
* try {</b>
|
||||
* while (count == 0)
|
||||
* <b>notEmpty.await();</b>
|
||||
* Object x = items[takeptr];
|
||||
* E x = (E) items[takeptr];
|
||||
* if (++takeptr == items.length) takeptr = 0;
|
||||
* --count;
|
||||
* <b>notFull.signal();</b>
|
||||
|
@ -310,7 +310,8 @@ public interface Condition {
|
|||
* the following form:
|
||||
*
|
||||
* <pre> {@code
|
||||
* boolean aMethod(long timeout, TimeUnit unit) {
|
||||
* boolean aMethod(long timeout, TimeUnit unit)
|
||||
* throws InterruptedException {
|
||||
* long nanos = unit.toNanos(timeout);
|
||||
* lock.lock();
|
||||
* try {
|
||||
|
@ -320,6 +321,7 @@ public interface Condition {
|
|||
* nanos = theCondition.awaitNanos(nanos);
|
||||
* }
|
||||
* // ...
|
||||
* return true;
|
||||
* } finally {
|
||||
* lock.unlock();
|
||||
* }
|
||||
|
@ -410,7 +412,8 @@ public interface Condition {
|
|||
* <p>The return value indicates whether the deadline has elapsed,
|
||||
* which can be used as follows:
|
||||
* <pre> {@code
|
||||
* boolean aMethod(Date deadline) {
|
||||
* boolean aMethod(Date deadline)
|
||||
* throws InterruptedException {
|
||||
* boolean stillWaiting = true;
|
||||
* lock.lock();
|
||||
* try {
|
||||
|
@ -420,6 +423,7 @@ public interface Condition {
|
|||
* stillWaiting = theCondition.awaitUntil(deadline);
|
||||
* }
|
||||
* // ...
|
||||
* return true;
|
||||
* } finally {
|
||||
* lock.unlock();
|
||||
* }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue