File tree 1 file changed +6
-2
lines changed
1 file changed +6
-2
lines changed Original file line number Diff line number Diff line change @@ -390,10 +390,14 @@ http://cs.oswego.edu/pipermail/concurrency-interest/2018-September/016526.html).
390
390
391
391
<a name =" unsafe-concurrent-iteration " ></a >
392
392
[ #] ( #unsafe-concurrent-iteration ) RC.3. A variation of the previous item: isn’t a non-thread-safe
393
- collection such as ` HashMap ` or ` ArrayList ` ** iterated outside of a critical section** , while it can
393
+ collection such as ` HashMap ` or ` ArrayList ` ** iterated outside of a critical section** , while it may
394
394
be modified concurrently? This could happen by accident when an ` Iterable ` , ` Iterator ` or ` Stream `
395
395
over a collection is returned from a method of a thread-safe class, even though the iterator or
396
- stream is created within a critical section.
396
+ stream is created within a critical section. Returning unmodifiable collection views like
397
+ ` Collections.unmodifiableList() ` from getters wrapping collection fields that may be modified
398
+ concurrently is subject to the same problem. If the collection is relatively small, it should be
399
+ copied entirely, or a copy-on-write collection (see [ Sc.3] ( #non-blocking-collections ) ) should be
400
+ used instead of a non-thread-safe collection.
397
401
398
402
Like the previous item, this one applies to growing ArrayLists too.
399
403
You can’t perform that action at this time.
0 commit comments