diff --git a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/EntityImpl.java b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/EntityImpl.java index 736211b4..f62c570b 100644 --- a/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/EntityImpl.java +++ b/aws-xray-recorder-sdk-core/src/main/java/com/amazonaws/xray/entities/EntityImpl.java @@ -431,8 +431,11 @@ public List getSubsegments() { @Override public void addSubsegment(Subsegment subsegment) { checkAlreadyEmitted(); - synchronized (subsegments) { + getSubsegmentsLock().lock(); + try { subsegments.add(subsegment); + } finally { + getSubsegmentsLock().unlock(); } } @@ -440,8 +443,11 @@ public void addSubsegment(Subsegment subsegment) { public void addException(Throwable exception) { checkAlreadyEmitted(); setFault(true); - synchronized (subsegments) { + getSubsegmentsLock().lock(); + try { cause.addExceptions(creator.getThrowableSerializationStrategy().describeInContext(exception, subsegments)); + } finally { + getSubsegmentsLock().unlock(); } } @@ -606,8 +612,11 @@ public String prettySerialize() { @Override public void removeSubsegment(Subsegment subsegment) { - synchronized (subsegments) { - getSubsegments().remove(subsegment); + getSubsegmentsLock().lock(); + try { + subsegments.remove(subsegment); + } finally { + getSubsegmentsLock().unlock(); } getParentSegment().getTotalSize().decrement(); }