Collection being updated while performing stream operation java 8 -
i have list
of objects being updated on regular basis couple of threads. while being updated want use stream filter elements out.
for example; have list being updated regularly:
list<myobject> mylist
now @ point in time use stream on list
list<myobject> result = mylist.stream().filter(myobj->myobjt.isvalid()).collect(tolist());
is thread-safe given list being update couple of threads?
the javadoc of copyonwritearraylist states following:
the "snapshot" style iterator method uses reference state of array @ point iterator created. array never changes during lifetime of iterator, interference impossible , iterator guaranteed not throw concurrentmodificationexception. iterator not reflect additions, removals, or changes list since iterator created.
so, yes, code should threadsafe. stream ignore additions list after has started.
Comments
Post a Comment