1515
1616import static com .alibaba .dcm .internal .InetAddressCacheUtilCommons .NEVER_EXPIRATION ;
1717import static com .alibaba .dcm .internal .InetAddressCacheUtilCommons .toInetAddressArray ;
18+ import static com .alibaba .dcm .internal .TimeUtil .convertNanoTimeToTimeMillis ;
19+ import static com .alibaba .dcm .internal .TimeUtil .getNanoTimeAfterMs ;
1820
1921/**
2022 * Util class to manipulate dns cache for {@code JDK 9+}.
@@ -39,7 +41,7 @@ public class InetAddressCacheUtilForJdk9Plus {
3941 */
4042 public static void setInetAddressCache (String host , String [] ips , long expireMillis )
4143 throws UnknownHostException , IllegalAccessException , InstantiationException , InvocationTargetException , ClassNotFoundException , NoSuchFieldException {
42- long expiration = expireMillis == NEVER_EXPIRATION ? NEVER_EXPIRATION : System . nanoTime () + expireMillis * 1000000 ;
44+ long expiration = expireMillis == NEVER_EXPIRATION ? NEVER_EXPIRATION : getNanoTimeAfterMs ( expireMillis ) ;
4345 Object cachedAddresses = newCachedAddresses (host , ips , expiration );
4446
4547 getCacheFieldOfInetAddress ().put (host , cachedAddresses );
@@ -178,12 +180,6 @@ public static DnsCache listInetAddressCache()
178180 return new DnsCache (retCache , retNegativeCache );
179181 }
180182
181- /**
182- * recorder jvm start timestamp point
183- */
184- private static final long JVM_START_NANO_SECONDS = System .nanoTime ();
185- private static final long JVM_START_MILL_SECONDS = System .currentTimeMillis ();
186-
187183 private static final String inetAddress$CachedAddresses_ClassName = "java.net.InetAddress$CachedAddresses" ;
188184 private static final String inetAddress$NameServiceAddresses_ClassName = "java.net.InetAddress$NameServiceAddresses" ;
189185
@@ -245,9 +241,8 @@ public static DnsCache listInetAddressCache()
245241 if (addressesClassName .equals (inetAddress$CachedAddresses_ClassName )) {
246242 inetAddressArray = (InetAddress []) inetAddressesFieldOfInetAddress$CacheAddress .get (addresses );
247243
248- long expirationNanos = (Long ) expiryTimeFieldOfInetAddress$CacheAddress .get (addresses );
249- // expiration timestamp convert
250- expiration = (expirationNanos - JVM_START_NANO_SECONDS ) / 1000000 + JVM_START_MILL_SECONDS ;
244+ long expiryTimeNanos = (Long ) expiryTimeFieldOfInetAddress$CacheAddress .get (addresses );
245+ expiration = convertNanoTimeToTimeMillis (expiryTimeNanos );
251246 } else if (addressesClassName .equals (inetAddress$NameServiceAddresses_ClassName )) {
252247 InetAddress inetAddress = (InetAddress ) reqAddrFieldOfInetAddress$NameServiceAddress .get (addresses );
253248 inetAddressArray = new InetAddress []{inetAddress };
0 commit comments