Closed catap closed 7 months ago
Here a quite trivial reorganization of OpenHashSet which allows it to be used on that way:
OpenHashSet
public static void main(String[] args) { LongSet original = new LongOpenHashSet(); LongSet readOnly = LongSets.unmodifiable(original); LongSet writable = LongSets.synchronize(original); SplittableRandom random = new SplittableRandom(); AtomicBoolean failure = new AtomicBoolean(); new Thread(() -> { while (true) { try { readOnly.contains(random.nextLong()); } catch (Throwable th) { failure.set(true); break; } } }).start(); new Thread(() -> { while (!failure.get()) { writable.add(random.nextLong()); } }).start(); }
The goal is crash at OutOfMemory, and not because of concurent access.
Sorry, I really don't think it's a good idea.
np, it is hack, yes.
Here a quite trivial reorganization of
OpenHashSet
which allows it to be used on that way:The goal is crash at OutOfMemory, and not because of concurent access.