Integer getElement( List<Integer> list ) {
int i = Random.getInt( list.size() );
return list.get( i );
}
The question: while this function has been called from a thread, IS there a way the list passed to this function can be modified by another thread?
No.
java.util.Listdoesn’t guarantee thread safety. The list can be changed betweenlist.size()andlist.get()by another thread. Moreover memory inconsistency is also a problem.I could think three ways to solve it: