Skip to content

Commit

Permalink
Fix a data race in the profiler that could lead to an NPE, and preven…
Browse files Browse the repository at this point in the history
…t the profiles from being captured.
  • Loading branch information
chrisvest committed Nov 27, 2018
1 parent 94a0271 commit a76b7a1
Showing 1 changed file with 4 additions and 4 deletions.
Expand Up @@ -20,10 +20,10 @@
package org.neo4j.resources; package org.neo4j.resources;


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,12 +51,12 @@ 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();
} }
samplerThreads.clear();
} }


@Override @Override
Expand Down

0 comments on commit a76b7a1

Please sign in to comment.