当前位置: 首页 > news >正文

免费发广告帖子的网站北京赛车网站建设

免费发广告帖子的网站,北京赛车网站建设,全屋定制十大名牌衣柜,wordpress菜单选项如何链接在JAVA中使用InetAddress.getByName(String host) 方法来获取给定hostname的IP地址。为了减少DNS解析的请求次数#xff0c;提高解析效率#xff0c;InetAddress中提供cache来缓存解析结果。 下面就此cache进行简单的分析#xff1a; 该缓存实现比较简单#xff0c;巧妙的利…在JAVA中使用InetAddress.getByName(String host) 方法来获取给定hostname的IP地址。为了减少DNS解析的请求次数提高解析效率InetAddress中提供cache来缓存解析结果。 下面就此cache进行简单的分析 该缓存实现比较简单巧妙的利用LinkedHashMap的特性来进行过期条目的检测和移除。 /*** Represents a cache entry*/static final class CacheEntry {CacheEntry(Object address, long expiration) {this.address address;this.expiration expiration;}Object address;long expiration;}//CacheEntry实例代表一个缓存记录一个记录中包括addressIP 地址 和 expiration/*** A cache that manages entries based on a policy specified* at creation time.*/static final class Cache {private LinkedHashMap cache;private Type type;enum Type {Positive, Negative};//此缓存只提供两种缓存类型 Positive: DNS解析成功 NegativeDNS解析失败/*** Create cache*/public Cache(Type type) {this.type type;cache new LinkedHashMap();//LinkedHashMap 保存了记录的插入顺序当遍历LindedHashMap时得到的数据是最先插入的数据此特性很重要在put方法中有所体现}private int getPolicy() {//获取配置的缓存策略 0: 不缓存 -1: 代表永久缓存 1代表缓存的时间(unit: second)if (type Type.Positive) {return InetAddressCachePolicy.get();} else {return InetAddressCachePolicy.getNegative();}}/*** Add an entry to the cache. If theres already an* entry then for this host then the entry will be* replaced.*/public Cache put(String host, Object address) {int policy getPolicy();if (policy InetAddressCachePolicy.NEVER) {return this;}// purge any expired entriesif (policy ! InetAddressCachePolicy.FOREVER) {// As we iterate in insertion order we can// terminate when a non-expired entry is found.LinkedList expired new LinkedList();Iterator i cache.keySet().iterator();//每次put的时候都对缓存记录做一个清理由于每个条目的过期时间是一样的所以先插入的记录就先到期long now System.currentTimeMillis();while (i.hasNext()) {String key (String)i.next();CacheEntry entry (CacheEntry)cache.get(key);if (entry.expiration 0 entry.expiration now) {expired.add(key);} else {break;}}i expired.iterator();while (i.hasNext()) {cache.remove(i.next());}}// create new entry and add it to the cache// -- as a HashMap replaces existing entries we// dont need to explicitly check if there is// already an entry for this host.long expiration;if (policy InetAddressCachePolicy.FOREVER) {expiration -1;} else {expiration System.currentTimeMillis() (policy * 1000);}CacheEntry entry new CacheEntry(address, expiration);cache.put(host, entry);return this;}/*** Query the cache for the specific host. If found then* return its CacheEntry, or null if not found.*/public CacheEntry get(String host) {int policy getPolicy();if (policy InetAddressCachePolicy.NEVER) {return null;}CacheEntry entry (CacheEntry)cache.get(host);// check if entry has expiredif (entry ! null policy ! InetAddressCachePolicy.FOREVER) {//命中缓存条目后先判断是否过期if (entry.expiration 0 entry.expiration System.currentTimeMillis()) {cache.remove(host);entry null;}}return entry;}}  转载于:https://www.cnblogs.com/cruze/p/3707011.html
http://wiki.neutronadmin.com/news/288908/

相关文章:

  • 怎样做网站公司免费windows云电脑
  • 计算机科学与技术 开题报告 网站建设平面设计哪里学
  • 傻瓜式做网站程序网站推广话术与技巧
  • 哪里网站可以做微信头像制作手机网站用什么软件
  • 景安企业网站建设给客户做非法网站
  • 甘肃城乡建设厅网站网站seo排名优化
  • 深圳市网站备案网页设计实验报告摘要
  • app模板网站模板网络规划设计师案例分析
  • 宣城网站seo诊断沈阳建设工程信息网招标显示待验证什么意思
  • 湛江北京网站建设学编程要会英语吗
  • 小地方做外卖网站怎样世界网站制作
  • 石河子做网站wordpress term id
  • 有哪些公司建设网站磁贴式网站模板
  • wordpress更改轮播图百度关键词优化快速排名软件
  • 网站建设最新教程视频wordpress支持国内视频的编辑器
  • 免费的网站后台陕西省城乡住房建设部网站
  • 宁德做网站怎样做美食网站
  • 西安+美院+网站建设seo推广是什么意思呢
  • 成都网络优化网站建设seo公司推荐
  • js做的携程网站建立什么网站
  • 网站单页模板怎么安装北京到牡丹江
  • 南京金九建设集团网站连云港网站关键词优化
  • 腾讯建站官网人才网站建设方案
  • 北京大兴网站建设做微视频的网站
  • 企业网站的重要性书签图片
  • 全球最好的设计网站wordpress加背景音乐
  • 中国设计网站排行榜创建个人网站制作流程步骤
  • 汽车网站页面设计优购物官方网上商城
  • 网站可视化编辑徐州 商城网站建设
  • crm网站下载商贸公司企业简介模板