diff --git a/src/main/java/io/netty/buffer/api/LifecycleTracer.java b/src/main/java/io/netty/buffer/api/LifecycleTracer.java index 123844a..92408ef 100644 --- a/src/main/java/io/netty/buffer/api/LifecycleTracer.java +++ b/src/main/java/io/netty/buffer/api/LifecycleTracer.java @@ -83,10 +83,12 @@ abstract class LifecycleTracer { } void addTrace(Trace trace) { - if (traces.size() == MAX_TRACE_POINTS) { - traces.pollFirst(); + synchronized (traces) { + if (traces.size() == MAX_TRACE_POINTS) { + traces.pollFirst(); + } + traces.addLast(trace); } - traces.addLast(trace); } @Override @@ -118,9 +120,11 @@ abstract class LifecycleTracer { @Override E attachTrace(E throwable) { - long timestamp = System.nanoTime(); - for (Trace trace : traces) { - trace.attach(throwable, timestamp); + synchronized (traces) { + long timestamp = System.nanoTime(); + for (Trace trace : traces) { + trace.attach(throwable, timestamp); + } } return throwable; }