gpt4 book ai didi

java - net.sourceforge.jtds.jdbc.cache.SimpleLRUCache 导致内存泄漏

转载 作者:行者123 更新时间:2023-12-01 15:21:32 28 4
gpt4 key购买 nike

我对使用 jtds 连接驱动程序非常陌生。我编写了一个应用程序,它读取大约 2500 个大型 xml,并进行 SQL 查询并针对 SQL 服务器运行。我发现当我达到一定数量的 xml 时,我的程序运行内存不足。我使用内存分析器在 eclipse 中检查了 phd 转储文件,发现 net.sourceforge.jtds.jdbc.cache.SimpleLRUCache 占用了大量内存。我连接到 SQL Server 一次并保持连接 Activity ,直到刷新所有查询。下面是我对服务器运行查询的代码。我不知道如何获取 net.sourceforge.jtds.jdbc.cache.SimpleLRUCache 类的句柄,因为它有一个明确的方法,我认为它可能会清除缓存。再说一遍,我对 jtds 驱动程序不是很了解。谁能帮我解决这个问题吗?

public boolean runQueries(String query){
if (getConn() != null && query != null) {
Statement statement = null;
try {
long start = System.currentTimeMillis();
try {
if(log.isLoggable(Level.FINEST)){
log.finest("Processing: "+query);
}
statement = getConn().createStatement();
statement.executeUpdate(query);
} catch (Exception e) {
if(log.isLoggable(Level.FINEST)){
log.log(Level.SEVERE, "Failed to process query: "
+ query, e);
}else{
String reportQuery = query.length() > MAX_CHARS_DISPLAY ? query.substring(0,MAX_CHARS_DISPLAY)+"..." : query;
log.log(Level.SEVERE, "Failed to process query: "
+ reportQuery , e);
}
}finally{
if(statement != null){
try {
statement.close();
} catch (SQLException e) {
log.log(Level.SEVERE,"Failed to close statement: ",e);
}
}
}

long end = System.currentTimeMillis();

return true;
}finally{
if(statement != null){
try {
statement.close();
} catch (SQLException e) {
log.log(Level.SEVERE,"Failed to close statement: ",e);
}
}
}
}
return false;
}

最佳答案

FAQ说明如何通过在 JDBC URL 中设置较低的 maxStatements 值来更改语句缓存的大小。如果您正在构建非常大的语句,您可能需要将该限制设置为远低于默认值 500。您还可能需要查看其中的一些其他内存设置。

关于java - net.sourceforge.jtds.jdbc.cache.SimpleLRUCache 导致内存泄漏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10842809/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com