#scala #concurrency
Вопрос:
Я пытаюсь понять следующее заявление из официального документа:
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.
Означает ли это, что я получаю снимок только в тот момент, когда начинаю получать доступ/читать некоторые ключи? Вместо снимка в момент моего звонкаreadOnlySnapshot()
?Note that the snapshot itself is never rewritten unlike when calling the snapshot method, but the obtained snapshot cannot be modified.
Что было бы хорошим примером для демонстрации этого?
Здесь могут помочь некоторые примеры кода.