jdk中的一个缓冲池

Posted by 猪头小队长 | 程序设计 | Friday 14 January 2005 16:15

为了程序的灵活,在使用new Socket(host, port)时候,没有将host直接设置为ip地址,而是使用了hostname,也就是修改了/etc/hosts这个文件。在程序的运行过程中,修改了hosts这个文件以后,发现程序并没有更改目标主机地址。

通过jdk的源代码,可以将new Socket对象的操作跟踪至InetAddress.getCachedAddress(String hostname),会发现jdk将其使用LinkedHashMap作了缓冲处理。

如果想在java里面编写灵活的程序,在采取某些技巧之前先大致看看源码,看是否jdk在底层不允许这种灵活。

[@more@]

No Comments

No comments yet.

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.