I am trying to understand the following statement from the official doc:
https://www.scala-lang.org/api/current/scala/collection/concurrent/TrieMap.html
/** Returns a read-only snapshot of this TrieMap. This operation is lock-free
* and linearizable.
*
* The snapshot is lazily updated - the first time some branch of this TrieMap are
* accessed, it is rewritten. The work of creating the snapshot is thus
* distributed across subsequent updates and accesses on this TrieMap by all
* threads. Note that the snapshot itself is never rewritten unlike when calling
* the snapshot method, but the obtained snapshot cannot be modified.
*/
def readOnlySnapshot(): collection.Map[K, V]
The snapshot is lazily updated - the first time some branch of this TrieMap are accessed, it is rewritten.
Does this mean that I only get the snapshot at the time I start to access/read some of the keys? Rather than the snapshot at the time I callreadOnlySnapshot()
?Note that the snapshot itself is never rewritten unlike when calling the snapshot method, but the obtained snapshot cannot be modified.
What would be a good example to demonstrate this?
Some code examples might help here.