Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,24 @@
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Threads;

import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;

public class GraphMutation {

public static class GraphNode {
private final Queue<GraphNode> nodes = new ConcurrentLinkedQueue<>();
private volatile ConcurrentLinkedQueue<GraphNode> nodes = new ConcurrentLinkedQueue<>();
private final AtomicLong linkCount = new AtomicLong(0);

public void link(GraphNode node) {
nodes.add(node);

// Switch to new data structure every 100,000 operations
// Other threads can finish with the old one
if (linkCount.incrementAndGet() % 100000 == 0) {
nodes = new ConcurrentLinkedQueue<>();
}
}
}

Expand Down
Loading