public class InetAddressCacheUtil extends Object
InetAddress.Cache#cache
in InetAddress.addressCache
.
Caution: InetAddress.addressCache
MUST
be guarded by InetAddress.addressCache
to avoid multithreaded problem,
you can see the implementation of InetAddress
to confirm this
(See Also lists key code of InetAddress
related to this point).InetAddress
,
InetAddress.addressCache
,
InetAddress.CacheEntry
,
InetAddress.cacheInitIfNeeded()
,
InetAddress.cacheAddresses(String, InetAddress[], boolean)
Modifier and Type | Method and Description |
---|---|
static void |
clearInetAddressCache() |
static int |
getDnsCachePolicy() |
static int |
getDnsNegativeCachePolicy() |
static DnsCacheEntry |
getInetAddressCache(String host) |
static DnsCache |
listInetAddressCache() |
static void |
removeInetAddressCache(String host) |
static void |
setDnsCachePolicy(int cacheSeconds)
Set JVM DNS cache policy
|
static void |
setDnsNegativeCachePolicy(int negativeCacheSeconds)
Set JVM DNS negative cache policy
|
static void |
setInetAddressCache(String host,
String[] ips,
long expiration)
Need convert host to lowercase, see
InetAddress.cacheAddresses(String, InetAddress[], boolean) . |
public static void setInetAddressCache(String host, String[] ips, long expiration) throws NoSuchMethodException, UnknownHostException, IllegalAccessException, InstantiationException, InvocationTargetException, ClassNotFoundException, NoSuchFieldException
InetAddress.cacheAddresses(String, InetAddress[], boolean)
.public static void removeInetAddressCache(String host) throws NoSuchFieldException, IllegalAccessException
@Nullable public static DnsCacheEntry getInetAddressCache(String host) throws NoSuchFieldException, IllegalAccessException
public static DnsCache listInetAddressCache() throws NoSuchFieldException, IllegalAccessException
public static void clearInetAddressCache() throws NoSuchFieldException, IllegalAccessException
public static void setDnsCachePolicy(int cacheSeconds) throws NoSuchFieldException, IllegalAccessException
cacheSeconds
- set default dns cache time. Special input case:
-1
means never expired.(In effect, all negative value)0
never cached.NoSuchFieldException
IllegalAccessException
InetAddressCachePolicy
,
InetAddressCachePolicy.cachePolicy
public static int getDnsCachePolicy() throws NoSuchFieldException, IllegalAccessException
public static void setDnsNegativeCachePolicy(int negativeCacheSeconds) throws NoSuchFieldException, IllegalAccessException
negativeCacheSeconds
- set default dns cache time. Special input case:
-1
means never expired.(In effect, all negative value)0
never cached.NoSuchFieldException
IllegalAccessException
InetAddressCachePolicy
,
InetAddressCachePolicy.negativeCachePolicy
public static int getDnsNegativeCachePolicy() throws NoSuchFieldException, IllegalAccessException
Copyright © 2015 Alibaba. All rights reserved.