Eclipse的字符串分区共享优化机制
http://tech.ddvip.com 2006年11月20日 社区交流
本文详细介绍Eclipse的字符串分区共享优化机制
为此 Eclipse 舍弃了 JVM 一级的字符串共享优化机制,而通过提供细粒度、完全可控、可测量的字符串分区共享优化机制,一定程度上缓解此问题。Eclipse 核心的 IStringPoolParticipant 接口由使用者显式实现,在其 shareStrings 方法中提交需要共享的字符串。
代码:
//
// org.eclipse.core.runtime.IStringPoolParticipant
//
public interface IStringPoolParticipant {
/**
* Instructs this participant to share its strings in the provided
* pool.
*/
public void shareStrings(StringPool pool);
}例如 MarkerInfo 类型实现了 IStringPoolParticipant 接口,在其 shareStrings 方法中,提交自己需要共享的字符串 type,并通知其下级节点进行相应的提交。
代码:
//
// org.eclipse.core.internal.resources.MarkerInfo
//
public class MarkerInfo implements ..., IStringPoolParticipant
{
public void shareStrings(StringPool set) {
type = set.add(type);
Map map = attributes;
if (map instanceof IStringPoolParticipant)
((IStringPoolParticipant) map).shareStrings(set);
}
}这样一来,只要一个对象树各级节点选择性实现 IStringPoolParticipant 接口,就可以一次性将所有需要共享的字符串,通过递归提交到一个字符串缓冲池中进行复用优化。如 Workspace 就是这样一个字符串共享根入口,其 open 方法在完成工作区打开操作后,将需要进行字符串共享优化的缓存管理对象,加入到全局字符串缓冲区分区优化列表中。
来源:JAVAEYE 责编:豆豆技术应用
正在加载评论...