Java强引用、 软引用、 弱引用、虚引用(三)

2014-11-24 08:36:54 · 作者: · 浏览: 2
loyee) ref.get();
49
}
50
// 如果没有软引用,或者从软引用中得到的实例是 null,重新构建一个实例,
51
// 并保存对这个新建实例的软引用
52
if (em == null ) {
53
em = new Employee(ID);
54
System. out .println( "Retrieve From EmployeeInfoCenter. ID=" + ID);
55
this .cacheEmployee(em);
56
}
57
return em;
58
}
59

60
// 清除那些所软引用的 Employee对象已经被回收的 EmployeeRef对象
61
private void cleanCache() {
62
EmployeeRef ref = null ;
63
while ((ref = (EmployeeRef) q .poll()) != null ) {
64
employeeRefs .remove(ref. _key );
65
}
66
}
67
}
作者:爱国者