2019独角兽企业重金招聘Python工程师标准>>>
1.缓存Cache
1.1.操作系统磁盘缓存(减少磁盘机械操作)
1.2.数据库缓存(减少文件系统I/0)
1.3.应用程序缓存(减少对数据库的查询)
1.4.Web服务器缓存(减少应用服务器请求)
1.5.客户端浏览器缓存(减少对网站的访问)
2.缓存一般需要设置时间戳,缓存值,过期时间(线程用来监控实体)
3.continue和break区别:continue是跳过此次循环,执行下次循环;break是跳出此次循环,执行循环外的语句
4.map的两个遍历方法
4.1.keySet()遍历map中的key
4.2.entrySet()遍历map中的key=value
5.Hashtable是过期的集合类,现在用ConcurrentHashMap(相当于分成多个Hashtable,采用分段锁)替代
continue和break实例
int x = 0;
int y = 0;
k:while (x++ < 10) {
if (x == 3) {
break k;
}
System.out.println("break:" + x);
}
while (y++ < 10) {
if (y == 3) {
continue;
}
System.out.println("continue:" + y);
}
输出结果
break:1
break:2
continue:1
continue:2
continue:4
continue:5
continue:6
continue:7
continue:8
continue:9
continue:10
EHCache实例
package com.ninemax.ak.cache;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.Element;
public class EHCache {
public static void main(String[] args) {
// 创建缓存管理器
CacheManager cacheManager = CacheManager.create();
// 创建缓存实例
Cache cache = new Cache("testCache", 5000, false, false, 5, 2);
// 在缓存管理器中添加缓存实例
cacheManager.addCache(cache);
// 在缓存管理器中换区缓存实例
Cache cacheExample = cacheManager.getCache("testCache");
// 使用获取到的缓存实例
Element element = new Element("key1","value1");
// 添加缓存值
cacheExample.put(element);
cacheExample.put(new Element("key2","value2"));
// 获取缓存个数
int cacheSize = cacheExample.getSize();
System.out.println("cacheSize:" + cacheSize);
// 删除缓存
cacheExample.remove("key1");
System.out.println("cacheSize:" + cacheExample.getSize());
// 关闭缓存管理器
cacheManager.shutdown();
}
}
技术斗图交流群:260052172