public final class ConcurrentValue<T> extends Object
MainThread cv.set(1); Thread1 cv.acquire(3); Thread2 cv.acquire(4); Thread3 cv.acquire(100); Thread4 cv.acquire(new Object() { public boolean equals(Object other) { return other.equals(2) || other.equals(3); } }); Thread5 cv.acquire(1); ... // Thread 1,2,3 and 4 are blocked // Thread 5 isn't blocked. MainThread cv.set(3); // Thread 1 and 4 are unblocked. // Thread 2 and 3 are still blocked.
Constructor and Description |
---|
ConcurrentValue(T value) |
Modifier and Type | Method and Description |
---|---|
void |
acquire(Object accept)
Blocking call.
|
T |
get() |
void |
reevaluate()
Reevaluate the condition.
|
void |
set(T newValue)
Specify the new value.
|
public ConcurrentValue(T value)
public T get()
public void set(T newValue)
public void reevaluate()
acquire(Object)
and the parameter
passed changed. acquire(Object)
generates a reevaluation automatically.public void acquire(Object accept) throws InterruptedException
Return when value accept is equal to get()
.
InterruptedException
Copyright (c) 2014 Eike Stepper (Berlin, Germany) and others.
All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/epl-v10.html