I’m looking for an efficient way to implement a concurrent tree structure. If that helps, assume that I have a lot more read accesses than changes to the structure.
The tree should support these operations:
- Adding and removing nodes
- Sort branches every time a new node is inserted
- Iterate over all the nodes (without ConcurrentModificationException)
- Look up an element by path
Take a look at: Concurrent-Trees on Google code for a way to modify tree-like structures without locking.
The project provides Concurrent Radix and Suffix trees for Java. They supports concurrent reads and writes, and reads are lock-free. It works by applying patches to the tree atomically. While these types of tree might not be exactly what you want, the approach using "patching" as described in TreeDesign is useful for any kind of tree-like structure.
The trees are intended for high concurrency read-mostly use cases, where (say) a background thread might be inserting or deleting entries from the tree while many foreground threads would continue to traverse it unimpeded by the modifications.