Skip to content

Commit 5ed2a96

Browse files
obourgainwilkinsona
authored andcommitted
Make InMemoryTraceRepository thread-safe
Closes gh-3027
1 parent 8681a8a commit 5ed2a96

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/trace/InMemoryTraceRepository.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.springframework.boot.actuate.trace;
1818

19+
import java.util.ArrayList;
1920
import java.util.Collections;
2021
import java.util.Date;
2122
import java.util.LinkedList;
@@ -26,6 +27,7 @@
2627
* In-memory implementation of {@link TraceRepository}.
2728
*
2829
* @author Dave Syer
30+
* @author Olivier Bourgain
2931
*/
3032
public class InMemoryTraceRepository implements TraceRepository {
3133

@@ -40,20 +42,24 @@ public class InMemoryTraceRepository implements TraceRepository {
4042
* @param reverse flag value (default true)
4143
*/
4244
public void setReverse(boolean reverse) {
43-
this.reverse = reverse;
45+
synchronized (this.traces) {
46+
this.reverse = reverse;
47+
}
4448
}
4549

4650
/**
4751
* @param capacity the capacity to set
4852
*/
4953
public void setCapacity(int capacity) {
50-
this.capacity = capacity;
54+
synchronized (this.traces) {
55+
this.capacity = capacity;
56+
}
5157
}
5258

5359
@Override
5460
public List<Trace> findAll() {
5561
synchronized (this.traces) {
56-
return Collections.unmodifiableList(this.traces);
62+
return Collections.unmodifiableList(new ArrayList<Trace>(this.traces));
5763
}
5864
}
5965

0 commit comments

Comments
 (0)