Skip to content

Commit

Permalink
Save AtomicBoolean allocation in Arc
Browse files Browse the repository at this point in the history
There is no reason to use an atomic boolean in this case,
as there aren't any compareAndSwap (or similar) operations,
just plain reading and writing of the field, which means
a volatile boolean is perfectly fine
  • Loading branch information
geoand committed Apr 20, 2022
1 parent 731abc3 commit dda7265
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.function.Function;
import java.util.stream.Collectors;
import javax.enterprise.context.BeforeDestroyed;
Expand Down Expand Up @@ -168,7 +167,7 @@ public void destroy(ContextState state) {
}
if (state instanceof RequestContextState) {
RequestContextState reqState = ((RequestContextState) state);
reqState.isValid.set(false);
reqState.isValid = false;
synchronized (state) {
Map<Contextual<?>, ContextInstanceHandle<?>> map = ((RequestContextState) state).map;
// Fire an event with qualifier @BeforeDestroyed(RequestScoped.class) if there are any observers for it
Expand Down Expand Up @@ -228,11 +227,12 @@ private static Notifier<Object> createDestroyedNotifier() {
static class RequestContextState implements ContextState {

private final Map<Contextual<?>, ContextInstanceHandle<?>> map;
private final AtomicBoolean isValid;

private volatile boolean isValid;

RequestContextState(ConcurrentMap<Contextual<?>, ContextInstanceHandle<?>> value) {
this.map = Objects.requireNonNull(value);
this.isValid = new AtomicBoolean(true);
this.isValid = true;
}

@Override
Expand All @@ -243,7 +243,7 @@ public Map<InjectableBean<?>, Object> getContextualInstances() {

@Override
public boolean isValid() {
return isValid.get();
return isValid;
}

}
Expand Down

0 comments on commit dda7265

Please sign in to comment.