摘要 |
Multi-threaded access to a collection is synchronized without locking the collection for long periods of time. In one implementation, a collection is locked briefly to allow safe creation of a resource entry (or a placeholder entry) in the collection and then unlocked prior to the start of the resource build operation. As such, the collection is unlocked during the potentially long period of time required to build the resource (e.g., a data object) into the collection. Furthermore, during the build operation, access attempts to the same resource in the collection by other threads are forced to wait until the resource build is completed. Nevertheless, the collection itself is not locked during the resource build operation, so that other threads can access other resources within the collection without waiting.
|