【问题标题】:JEditorPane setText 2MB HTML ---> Terrible Performance !!! (65 seconds)JEdi​​torPane setText 2MB HTML ---> 糟糕的性能!!! (65 秒)
【发布时间】:2012-02-21 05:07:49
【问题描述】:

我正在尝试将大约 2MB(为精确起见为 1927KB)的 HTML 文件加载到 JEditorPane 中,大约需要 65 秒,这似乎是 JTextPane/JEditorPane 的错误,我有还阅读了网络上的几篇文章,例如this one,但我找不到解决方案...

这是我使用的代码:

final String htmlContent = //Load a 2MB String
previewPane.setContentType("text/html; charset=UTF-8");     
previewPane.setText(htmlContent);

setText 方法大约需要 65 秒才能完全执行,如您在我的应用程序日志中所见:

Set the html content(1927KB) of the Preview pane, loading time=68230ms
Set the html content(1927KB) of the Preview pane, loading time=62693ms
Set the html content(1927KB) of the Preview pane, loading time=66583ms

有没有办法解决这个问题?

在 Intel Core 2 Duo 2.93GHz 和 8GB DDR 3 RAM 上加载 2MB 文本大约需要 65 秒...

【问题讨论】:

  • //Load a 2MB String (read over next 3 life times) 什么用例证明加载近 2MB 的 HTML 是合理的?
  • 这是我想在 PreviewPane 中显示的报告内容,2MB 文件不是那么大...
  • 那是大量的 HTML。请记住,它必须经过处理。因此,即使 2MB 看起来并不多,在处理和创建所有 GUI 组件之后,内存占用量也会非常大。尝试使用浏览器或其他 HTML 编辑器打开 2MB HTML 并比较性能...
  • @aleroot :然后用 c++ 编写代码或试试这个 :wiki.eclipse.org/JFace 。它使用本机 GUI 组件,因此它比 swing 更好地工作。
  • @Alex Calugarescu:你是认真的吗?如果我在 Safari 或 Chrome 中打开文件,它需要将近 2 秒才能完全加载...

标签: java performance swing jeditorpane


【解决方案1】:

【讨论】:

  • 我已经尝试过这些技巧,但它们只改进了渲染阶段而不是加载阶段(seText)......在我的问题中,我已经指定我已经尝试过这些技巧......
  • 如果只加载 Document 会发生什么?加载纯新创建的 Document 需要多少时间?通过调用 textPane.setDocument(docInstance) 渲染 Document 需要多少时间?
  • 在预览窗格中设置html内容(1927KB),加载时间=109051ms 比较差。
猜你喜欢
  • 2013-04-02
  • 2011-06-06
  • 1970-01-01
  • 2011-08-20
  • 2012-07-29
  • 2021-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多