Skip to content

Commit

Permalink
fix JvmFilterHolder concurrent safe problem
Browse files Browse the repository at this point in the history
  • Loading branch information
致节 committed Mar 6, 2024
1 parent 43cd56a commit 9356703
Showing 1 changed file with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@

import org.springframework.core.annotation.AnnotationAwareOrderComparator;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;

/**
Expand All @@ -31,7 +30,7 @@
*/
public class JvmFilterHolder {

private final List<JvmFilter> JVM_FILTERS = new ArrayList<>();
private final List<JvmFilter> JVM_FILTERS = new CopyOnWriteArrayList<>();

private final AtomicBoolean FILTERS_SORTED = new AtomicBoolean(false);

Expand All @@ -56,8 +55,8 @@ public List<JvmFilter> getJvmFilters() {
}

public static boolean beforeInvoking(JvmFilterContext context) {
List<JvmFilter> filters = Collections.unmodifiableList(context.getSofaRuntimeContext()
.getJvmFilterHolder().getJvmFilters());
List<JvmFilter> filters = context.getSofaRuntimeContext().getJvmFilterHolder()
.getJvmFilters();
for (JvmFilter filter : filters) {
if (!filter.before(context)) {
return false;
Expand All @@ -67,8 +66,8 @@ public static boolean beforeInvoking(JvmFilterContext context) {
}

public static boolean afterInvoking(JvmFilterContext context) {
List<JvmFilter> filters = Collections.unmodifiableList(context.getSofaRuntimeContext()
.getJvmFilterHolder().getJvmFilters());
List<JvmFilter> filters = context.getSofaRuntimeContext().getJvmFilterHolder()
.getJvmFilters();
for (int i = filters.size() - 1; i >= 0; --i) {
if (!filters.get(i).after(context)) {
return false;
Expand Down

0 comments on commit 9356703

Please sign in to comment.