...
Code Block | ||
---|---|---|
| ||
final class IPHolder { private final List<InetAddress> ips = Collections.synchronizedList(new ArrayList<InetAddress>()); public void addIPAddressaddAndPrintIPAddresses(InetAddress address) { synchronized (ips) { ips.add(address); } } public void addAndPrintIPAddresses(InetAddress address) { synchronized (ips) { addIPAddress(address); InetAddress[] addressCopy = (InetAddress[]) ips.toArray(new InetAddress[0]); // Iterate through array addressCopy ... } } } |
...