src/share/classes/java/net/InetAddress.java
Print this page
*** 675,686 ****
static InetAddress[] unknown_array; // put THIS in cache
static InetAddressImpl impl;
! private static HashMap<String, InetAddress[]> lookupTable
! = new HashMap<String, InetAddress[]>();
/**
* Represents a cache entry
*/
static final class CacheEntry {
--- 675,685 ----
static InetAddress[] unknown_array; // put THIS in cache
static InetAddressImpl impl;
! private static final HashMap<String, Void> lookupTable = new HashMap<>();
/**
* Represents a cache entry
*/
static final class CacheEntry {
*** 735,745 ****
if (policy != InetAddressCachePolicy.FOREVER) {
// As we iterate in insertion order we can
// terminate when a non-expired entry is found.
! LinkedList<String> expired = new LinkedList<String>();
long now = System.currentTimeMillis();
for (String key : cache.keySet()) {
CacheEntry entry = cache.get(key);
if (entry.expiration >= 0 && entry.expiration < now) {
--- 734,744 ----
if (policy != InetAddressCachePolicy.FOREVER) {
// As we iterate in insertion order we can
// terminate when a non-expired entry is found.
! LinkedList<String> expired = new LinkedList<>();
long now = System.currentTimeMillis();
for (String key : cache.keySet()) {
CacheEntry entry = cache.get(key);
if (entry.expiration >= 0 && entry.expiration < now) {
*** 1225,1234 ****
--- 1224,1234 ----
// addressCache for any reason,
// it should add the host in the
// lookupTable and return null so the
// following code would do a lookup itself.
if ((addresses = checkLookupTable(host)) == null) {
+ try {
// This is the first thread which looks up the addresses
// this host or the cache entry for this host has been
// expired so this thread should do the lookup.
for (NameService nameService : nameServices) {
try {
*** 1256,1288 ****
}
}
// Cache the addresses.
cacheAddresses(host, addresses, success);
- // Delete the host from the lookupTable, and
- // notify all threads waiting for the monitor
- // for lookupTable.
- updateLookupTable(host);
if (!success && ex != null)
throw ex;
}
return addresses;
}
private static InetAddress[] checkLookupTable(String host) {
- // make sure addresses is null.
- InetAddress[] addresses = null;
-
synchronized (lookupTable) {
// If the host isn't in the lookupTable, add it in the
// lookuptable and return null. The caller should do
// the lookup.
if (lookupTable.containsKey(host) == false) {
lookupTable.put(host, null);
! return addresses;
}
// If the host is in the lookupTable, it means that another
// thread is trying to look up the addresses of this host.
// This thread should wait.
--- 1256,1286 ----
}
}
// Cache the addresses.
cacheAddresses(host, addresses, success);
if (!success && ex != null)
throw ex;
+ } finally {
+ // Delete host from the lookupTable and notify
+ // all threads waiting on the lookupTable monitor.
+ updateLookupTable(host);
}
+ }
return addresses;
}
private static InetAddress[] checkLookupTable(String host) {
synchronized (lookupTable) {
// If the host isn't in the lookupTable, add it in the
// lookuptable and return null. The caller should do
// the lookup.
if (lookupTable.containsKey(host) == false) {
lookupTable.put(host, null);
! return null;
}
// If the host is in the lookupTable, it means that another
// thread is trying to look up the addresses of this host.
// This thread should wait.
*** 1296,1309 ****
// The other thread has finished looking up the addresses of
// the host. This thread should retry to get the addresses
// from the addressCache. If it doesn't get the addresses from
// the cache, it will try to look up the addresses itself.
! addresses = getCachedAddresses(host);
if (addresses == null) {
synchronized (lookupTable) {
lookupTable.put(host, null);
}
}
return addresses;
}
--- 1294,1308 ----
// The other thread has finished looking up the addresses of
// the host. This thread should retry to get the addresses
// from the addressCache. If it doesn't get the addresses from
// the cache, it will try to look up the addresses itself.
! InetAddress[] addresses = getCachedAddresses(host);
if (addresses == null) {
synchronized (lookupTable) {
lookupTable.put(host, null);
+ return null;
}
}
return addresses;
}