我使用版本 6.4.0-jre8 的 mssql-jdbc 驱动程序。
我执行一个简单的 SELECT * 查询,该查询可能返回数百万行。为了避免 OOM 错误,我定义了 responseBuffering=adaptive
和 fetchSize=10000
。我还确保 ResultSet
为 type_fetch_only
和 concur_read_only
。尽管如此,我仍然收到 OOM 错误。堆大小立即飙升至 XMX 限制。
下面您可以找到内存转储分析。我想知道为什么 TDSPackets 没有尽早释放?
如果有任何关于如何避免 OOM 错误的建议,我将不胜感激。谢谢!
最佳答案
问题是我在同一个连接上同时执行多个查询。
Avoid executing more than one statement on the same connection simultaneously. Executing another statement before processing the results of the previous statement may cause the unprocessed results to be buffered into the application memory.
关于java - 连接到 MSSQL 消耗过多内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56491983/