...
Code Block | ||
---|---|---|
| ||
synchronized(ips) { ia = (InetAddress[]) ips.toArray(new InetAddress[0]); System.out.println("Number of IPs: " + ia.length); } |
Wiki Markup |
---|
Note that this advice applies to all {{Collection}} classes including the thread-safe hash tables. Enumerations of the objects of a {{Collection}} and iterators also require explicit synchronization on the {{Collection}} object or any single lock object. Although expensive, {{CopyOnWriteArrayList}} and {{CopyOnWriteArraySet}} classes may also be used to create copies of the core {{Collection}} so that iterators do not fail with a runtime exception when some data in the {{Collection}} is modified. \[[JavaThreads 04|AA. Java References#JavaThreads 04]\] |
Risk Assessment
Non-atomic code can induce race conditions and affect program correctness.
...