Skip to content

Commit

Permalink
Fix the FIXME I forgot
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <jorge.bescos.gascon@oracle.com>
  • Loading branch information
jbescos committed Jan 22, 2024
1 parent 25d8df1 commit c19f226
Showing 1 changed file with 4 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.ReentrantLock;

import org.glassfish.hk2.api.ActiveDescriptor;
Expand Down Expand Up @@ -64,6 +65,7 @@
public abstract class OperationContext<T extends Annotation> implements Context<T> {
private SingleOperationManager<T> manager;
private final ReentrantLock lock = new ReentrantLock();
private final Condition condition = lock.newCondition();
private final HashMap<OperationHandleImpl<T>, LinkedHashMap<ActiveDescriptor<?>, Object>> operationMap =
new HashMap<OperationHandleImpl<T>, LinkedHashMap<ActiveDescriptor<?>, Object>>();
private final HashSet<ActiveDescriptor<?>> creating = new HashSet<ActiveDescriptor<?>>();
Expand Down Expand Up @@ -141,8 +143,7 @@ public <U> U findOrCreate(ActiveDescriptor<U> activeDescriptor,
// retVal is null, and this is not an explicit null, so must actually do the creation
while (creating.contains(activeDescriptor)) {
try {
// FIXME Find other way to replace wait()
Thread.sleep(1);
condition.await();
}
catch (InterruptedException e) {
throw new RuntimeException(e);
Expand Down Expand Up @@ -181,6 +182,7 @@ public <U> U findOrCreate(ActiveDescriptor<U> activeDescriptor,
}

creating.remove(activeDescriptor);
condition.signalAll();
} finally {
lock.unlock();
}
Expand Down

0 comments on commit c19f226

Please sign in to comment.