如何禁用 Jsoup Tokeniser 中的错误跟踪?

发布于 2024-12-13 21:00:03 字数 398 浏览 2 评论 0原文

注意:这个问题涉及Jsoup 1.6.1

我需要使用Jsoup解析多个文档,但我注意到一段时间后内存会增加。使用堆转储和内存分析器,我已将问题追溯到 Jsoup 的 Tokeniser 类,该类存储了 ParseError 的 ArrayList 。在堆转储中,存储了超过 500 万个 ParseError 对象,每个对象大小为 56 字节。

查看源代码,我注意到 org.jsoup.parser.Tokeniser 中的一个变量允许关闭错误跟踪。按照调用流程,我看不到任何将其关闭的调用,尽管有一种方法可以这样做。该类不是公开的,我被迫修改源代码并从源代码构建它。

是否有我可以调用的方法或可以设置的属性来有效禁用 Tokeniser 中的错误跟踪,而无需修改源代码?

Note: This question refers to Jsoup 1.6.1

I need to parse several documents using Jsoup, but I have noticed the memory builds up after some time. Using heap dumps and a memory analyzer, I have tracked down the problem to Jsoup's Tokeniser class, which stores an ArrayList of ParseError's. In the heap dump, there were over 5 million of ParseError objects stored, at 56 bytes each.

Looking at the source code, I noticed a variable in org.jsoup.parser.Tokeniser which allows error tracking to be turned off. Following the flow of the calls, I can not see any call to turn it off, despite there being a method to do so. The class not being public, I am forced to modify the source code and build it from source.

Is there a method I can call or a property I can set to effectively disable error tracking in the Tokeniser without having to modify the source code?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

格子衫的從容 2024-12-20 21:00:03

事实证明该问题不是由 Jsoup 引起的。它尝试解析的文件不是 HTML 文件,而是图像。由于 Jsoup 并不打算检查它是否具有正确的文件类型,而是依赖程序员首先进行检查,因此这个问题的答案是 Jsoup 1.6.1,除非您修改源代码。关闭 Jsoup 的 Tokeniser 类中的错误跟踪确实减少了内存使用并提高了一点速度(由于没有在 ArrayList 中插入许多元素),但修改源代码并不能受到推崇的。如果您遇到此问题,请先检查您自己的代码。 ;)

Turns out the issue is not caused by Jsoup. The file it was trying to parse was not an HTML file but an image. Since Jsoup is not intended to check if it has the right type of file and relies on the programmer to check that in the first place, the answer to this question is in Jsoup 1.6.1, you can not unless you modify the source code. Turning off error tracking in Jsoup's Tokeniser class did reduce memory usage and improve speed a little (due to not inserting many elements in an ArrayList), but modifying the source code is not recommended. If you ever encounter this problem, check your own code first. ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文