added synchronization to HttpTraceRepository
This commit is contained in:
parent
2b602b0485
commit
07c159ddc1
|
@ -1,6 +1,7 @@
|
||||||
package com.baeldung.spring.boot.management.trace;
|
package com.baeldung.spring.boot.management.trace;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.springframework.boot.actuate.trace.http.HttpTrace;
|
import org.springframework.boot.actuate.trace.http.HttpTrace;
|
||||||
|
@ -14,14 +15,19 @@ public class CustomTraceRepository implements HttpTraceRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<HttpTrace> findAll() {
|
public List<HttpTrace> findAll() {
|
||||||
return traces;
|
synchronized (this.traces) {
|
||||||
|
return Collections.unmodifiableList(new ArrayList<>(this.traces));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void add(HttpTrace trace) {
|
public void add(HttpTrace trace) {
|
||||||
if ("GET".equals(trace.getRequest().getMethod())) {
|
if ("GET".equals(trace.getRequest()
|
||||||
traces.clear();
|
.getMethod())) {
|
||||||
traces.add(trace);
|
synchronized (this.traces) {
|
||||||
|
traces.clear();
|
||||||
|
traces.add(trace);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue