Skip to content

Commit

Permalink
Backport a data-race fix that could prevent profiles from being captu…
Browse files Browse the repository at this point in the history
…red.
  • Loading branch information
chrisvest committed Apr 2, 2019
1 parent f9c012a commit dadb6a9
Showing 1 changed file with 4 additions and 3 deletions.
Expand Up @@ -20,10 +20,10 @@
package org.neo4j.test.rule; package org.neo4j.test.rule;


import java.io.PrintStream; import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.PriorityQueue; import java.util.PriorityQueue;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
Expand All @@ -33,7 +33,7 @@ class SamplingProfiler implements Profiler
{ {
private static final long DEFAULT_SAMPLE_INTERVAL_NANOS = TimeUnit.MILLISECONDS.toNanos( 1 ); private static final long DEFAULT_SAMPLE_INTERVAL_NANOS = TimeUnit.MILLISECONDS.toNanos( 1 );


private final ArrayList<Thread> samplerThreads = new ArrayList<>(); private final ConcurrentLinkedQueue<Thread> samplerThreads = new ConcurrentLinkedQueue<>();
private final AtomicBoolean stopped = new AtomicBoolean(); private final AtomicBoolean stopped = new AtomicBoolean();
private final ConcurrentHashMap<Thread,Sample> samples = new ConcurrentHashMap<>(); private final ConcurrentHashMap<Thread,Sample> samples = new ConcurrentHashMap<>();
private final AtomicLong sampleIntervalNanos = new AtomicLong( DEFAULT_SAMPLE_INTERVAL_NANOS ); private final AtomicLong sampleIntervalNanos = new AtomicLong( DEFAULT_SAMPLE_INTERVAL_NANOS );
Expand All @@ -51,7 +51,8 @@ public void reset()
public void finish() throws InterruptedException public void finish() throws InterruptedException
{ {
stopped.set( true ); stopped.set( true );
for ( Thread thread : samplerThreads ) Thread thread;
while ( (thread = samplerThreads.poll()) != null )
{ {
thread.interrupt(); thread.interrupt();
thread.join(); thread.join();
Expand Down

0 comments on commit dadb6a9

Please sign in to comment.