From dadb6a992e7e02c3f16a71ef0f93152f393bcf0a Mon Sep 17 00:00:00 2001 From: Chris Vest Date: Tue, 2 Apr 2019 10:23:42 +0200 Subject: [PATCH] Backport a data-race fix that could prevent profiles from being captured. --- .../test/java/org/neo4j/test/rule/SamplingProfiler.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/community/io/src/test/java/org/neo4j/test/rule/SamplingProfiler.java b/community/io/src/test/java/org/neo4j/test/rule/SamplingProfiler.java index 7c7b7987486f8..efe380d9e22fd 100644 --- a/community/io/src/test/java/org/neo4j/test/rule/SamplingProfiler.java +++ b/community/io/src/test/java/org/neo4j/test/rule/SamplingProfiler.java @@ -20,10 +20,10 @@ package org.neo4j.test.rule; import java.io.PrintStream; -import java.util.ArrayList; import java.util.Map; import java.util.PriorityQueue; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicLong; @@ -33,7 +33,7 @@ class SamplingProfiler implements Profiler { private static final long DEFAULT_SAMPLE_INTERVAL_NANOS = TimeUnit.MILLISECONDS.toNanos( 1 ); - private final ArrayList samplerThreads = new ArrayList<>(); + private final ConcurrentLinkedQueue samplerThreads = new ConcurrentLinkedQueue<>(); private final AtomicBoolean stopped = new AtomicBoolean(); private final ConcurrentHashMap samples = new ConcurrentHashMap<>(); private final AtomicLong sampleIntervalNanos = new AtomicLong( DEFAULT_SAMPLE_INTERVAL_NANOS ); @@ -51,7 +51,8 @@ public void reset() public void finish() throws InterruptedException { stopped.set( true ); - for ( Thread thread : samplerThreads ) + Thread thread; + while ( (thread = samplerThreads.poll()) != null ) { thread.interrupt(); thread.join();