InetAddress should utilize networkaddress.cache.ttl for getLocalHost() too

Michael McMahon michael.x.mcmahon at oracle.com
Wed Jul 11 03:55:24 PDT 2012


On 11/07/12 08:00, Alan Bateman wrote:
> On 05/07/2012 07:10, Deven You wrote:
>> Hi All,
>>
>> I noticed that InetAddress.getLocalHost() uses cache to improve the 
>> performance. However the default implementation is caching local host 
>> within 5 seconds.
>>
>> From the spec, networkaddress.cache.ttl should be used to control the 
>> cache behaviour and I think it is a better solution.
>>
>> For example, if the networkaddress.cache.ttl is set to -1 which means 
>> always cache the local host then we can avoid unnecessary operations 
>> on getAddressesFromNameService to improve the performance.
>>
>> I have made a patch for this solution, so anyone would like to take a 
>> look?
>>
>> [1] http://cr.openjdk.java.net/~littlee/OJDK-527/webrev.00/ 
>> <http://cr.openjdk.java.net/%7Elittlee/OJDK-527/webrev.00/>
>> Thanks a lot!
>> -- 
>> Best Regards,
>>
>> Deven
> I'm not sure about this one as I suspect it will cause problems in 
> DHCP or any environments where the host addresses changes, say moving 
> to a different wireless network or waking up a machine after hibernation.
>
> -Alan

That's true. We updated the spec for the caching behavior a while back, 
and probably should have included this exception
for the local host. I agree that we shouldn't change the behavior. 
Perhaps, the 5 seconds could be configurable itself,
but I think it should be kept separate from the main caching behavior.

- Michael.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/net-dev/attachments/20120711/fb672a2f/attachment.html 


More information about the net-dev mailing list