I have a test code like this :
List list = new ArrayList<>(1000000);
for(int i=0;i<1000000;i++){
list.add(i);
}
List
values.add(String)
is not thread safe. When you invoke this method from different threads without synchronization it is no guarantee that it will work as expected.
To fix that you can:
Vector
or CopyOnWriteArrayLis
.synchronize(this){values.add(new Date().toString())}
into your code. Note i->
is outside synchronize blockIntStream.range(0, 1_000_000).parallel().mapToObj(i -> new Date().toString()).collect(Collectors.toList());