ArrayList is NOT ThreadSafe
sometimes you need to restrict access one thread at a time by implementing Synchronization.
Collection list3 = Collections.synchronizedList(Arrays.asList(1, 2, 3, 4, 5));
synchronized (list3) {
Iterator j = list3.iterator();
while (j.hasNext())
System.out.println(j.next());
}
No comments:
Post a Comment