ConcurrentSkipListSet Navigable Range Views
Query live sorted subSet ranges and atomic pollFirst entries on ConcurrentSkipListSet while concurrent mutations iterate safely without locks.
Code
import java.util.NavigableSet;
import java.util.concurrent.ConcurrentSkipListSet;
public class LivePrioritySet {
public static void main(String[] args) {
ConcurrentSkipListSet<Integer> priorities = new ConcurrentSkipListSet<>();
priorities.add(10);
priorities.add(25);
priorities.add(40);
priorities.add(55);
// Live bounded view [20, 50]: subsequent inserts inside the range appear automatically
NavigableSet<Integer> window = priorities.subSet(20, true, 50, true);
System.out.println("initial window: " + window);
// Weakly consistent iterator tolerates modifications during traversal without throwing
for (Integer p : priorities) {
if (p == 25) {
priorities.add(30);
priorities.remove(55);
}
}
System.out.println("updated window: " + window);
System.out.println("floor(26)=" + priorities.floor(26) + " ceiling(26)=" + priorities.ceiling(26));
// pollFirst atomically claims and removes the lowest element
Integer lowest = priorities.pollFirst();
System.out.println("polled lowest=" + lowest + " remaining=" + priorities);
}
}Behavior overview — ConcurrentSkipListSet Navigable Range Views
All of the logic lives in the class LivePrioritySet and the function main.
The cycling part of this snippet is for (Integer p : priorities).
What to watch for
- Structurally free of external dependencies — zero registries or lockfiles involved.
Using it
The entry-point signature is public static void main(String[] args)
Output lines are prefixed (initial window:, updated window:, floor(26)=), attaching clear runtime labels right next to observed values.
Key statements
ConcurrentSkipListSet<Integer> priorities = new ConcurrentSkipListSet<>();
NavigableSet<Integer> window = priorities.subSet(20, true, 50, true);
Integer lowest = priorities.pollFirst();
Interactive Tools for This Topic
SemVer Range CheckerCheck whether a semantic version satisfies an npm-style range such as caret, tilde, comparison sets, wildcards, or hyphen ranges.SRI Hash GeneratorGenerate Subresource Integrity (SRI) hashes from resource content using SHA-256, SHA-384, or SHA-512, and copy a ready-to-use script tag.
FAQ
- What does ConcurrentSkipListSet Navigable Range Views print when run?
- The script runs standalone; its 4 labeled outputs include `initial window:`, `updated window:`, `floor(26)=`.
Report a problem with this exampleOpens a pre-filled issue on GitHub.