优化xstream的加载速度
当我尝试从 XML 文件执行加载时,我感觉 xstream 加载速度达不到我的要求。为了 一个有 10k ++ 条目的“数据库”,需要几分钟。
以下是我用来序列化的整个数据结构。列表的大小(符号和代码)将为 大约 10k ++ 条目。
有吗我可以尝试一下这种方法,看看它是否会加快我的加载时间?仍然可以加载回来 以前保存的文件也很重要。
以下是用于反序列化的代码。谢谢。
@SuppressWarnings("unchecked")
public static <A> A fromXML(Class c, File file) {
XStream xStream = new XStream(new DomDriver("UTF-8"));
InputStream inputStream = null;
try {
inputStream = new java.io.FileInputStream(file);
Object object = xStream.fromXML(inputStream);
if (c.isInstance(object)) {
return (A)object;
}
}
catch (Exception exp) {
log.error(null, exp);
}
finally {
if (false == close(inputStream)) {
return null;
}
inputStream = null;
}
return null;
}
I felt xstream loading speed doesn't up to my requirement when I try to perform loading from the XML file. For
an "database" with 10k ++ entries, it will take several minutes.
The following is the entire data structure I use to serialize. Size of List (symbols and codes) will be
roughly 10k ++ entries.
Is there any approach I can try out, to see whether it will speed up my loading time? Able to still load back
previous saved file is important as well.
The following are the code used to de-serialization. Thanks.
@SuppressWarnings("unchecked")
public static <A> A fromXML(Class c, File file) {
XStream xStream = new XStream(new DomDriver("UTF-8"));
InputStream inputStream = null;
try {
inputStream = new java.io.FileInputStream(file);
Object object = xStream.fromXML(inputStream);
if (c.isInstance(object)) {
return (A)object;
}
}
catch (Exception exp) {
log.error(null, exp);
}
finally {
if (false == close(inputStream)) {
return null;
}
inputStream = null;
}
return null;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
避免使用速度慢的 DomDriver。
Avoid using slow DomDriver.