手机站
网通分站
电信主站
密 码:
用户名:
当前位置 : 主页>程序设计>Java技术>列表

Eclipse 的字符串分区共享优化机制

来源:互联网 作者:west263.com 时间:2008-02-23
西部数码-全国虚拟主机10强!40余项虚拟主机管理功能,全国领先!双线多线虚拟主机南北访问畅通无阻!免费赠送企业邮局,.CN域名,自助建站480元起,免费试用7天,满意再付款! P4主机租用799元/月.月付免压金!
;

if (result != null) {
if (result != string)
savings = 44 2 * string.length();
return (String) result;
}

map.put(string, string);
return string;
}

// 获取优化能节省多少空间的大致估算值
public int getSavedStringCount() {
return savings;
}
}


不过这里的估算值在某些情况下可能并不准确,例如缓冲池中包括字符串 S1,此时提交一个与之内容相同但物理位置不同的字符串 S2,则如果 S2 被提交多次,会导致错误的高估优化效果。当然如果需要得到精确值,也可以对其进行重构,通过一个 Set 跟踪每个字符串优化的过程,获得精确优化度量,但需要损失一定效率。

在了解了需优化字符串的提交流程,以及字符串提交后的优化流程后,我们接着看看 Eclipse 核心是如何将这两者整合到一起的。
前面提到 Workspace.open 方法会调用 InternalPlatform.addStringPoolParticipant 方法,将一个字符串缓冲池分区的根节点,添加到全局性的优化任务队列中。
java代码:


//
// org.eclipse.core.internal.runtime.InternalPlatform
//
public final class InternalPlatform {
private StringPoolJob stringPoolJob;

public void addStringPoolParticipant(IStringPoolParticipant participant, ISchedulingRule rule) {
if (stringPoolJob == null)
stringPoolJob = new StringPoolJob(); // Singleton 模式

stringPoolJob.addStringPoolParticipant(participant, rule);
}
}

//
// org.eclipse.core.internal.runtime.StringPoolJob
//
public class StringPoolJob extends Job
{
private static final long INITIAL_DELAY = 10000;//five seconds

private Map participants = Collections

文章整理:西部数码--专业提供域名注册虚拟主机服务
http://www.west263.com
以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!