added synchronization to HttpTraceRepository

This commit is contained in:
Marcos Lopez Gonzalez 2019-07-30 19:39:46 +02:00
parent 2b602b0485
commit 07c159ddc1
1 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,7 @@
package com.baeldung.spring.boot.management.trace;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.springframework.boot.actuate.trace.http.HttpTrace;
@ -14,14 +15,19 @@ public class CustomTraceRepository implements HttpTraceRepository {
@Override
public List<HttpTrace> findAll() {
return traces;
synchronized (this.traces) {
return Collections.unmodifiableList(new ArrayList<>(this.traces));
}
}
@Override
public void add(HttpTrace trace) {
if ("GET".equals(trace.getRequest().getMethod())) {
traces.clear();
traces.add(trace);
if ("GET".equals(trace.getRequest()
.getMethod())) {
synchronized (this.traces) {
traces.clear();
traces.add(trace);
}
}
}