0

我是使用 jtds 连接驱动程序的新手。我编写了一个应用程序,它读取大约 2500 个大型 xml,并进行 SQL 查询并针对 SQL 服务器运行。我已经看到,当我达到一定数量的 xml 时,我的程序运行内存不足。我使用内存分析器在 Eclipse 中检查了我的 phd 转储文件,发现 net.sourceforge.jtds.jdbc.cache.SimpleLRUCache 占用了大量内存。我连接到 SQL 服务器一次并保持连接活动,直到我刷新所有查询。下面是我对服务器运行查询的代码。我不知道如何获得 net.sourceforge.jtds.jdbc.cache.SimpleLRUCache 类的句柄,因为它有一个我认为可能会清除缓存的 clear 方法。同样,我对 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;
}
4

1 回答 1

1

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

于 2012-06-02T02:39:25.080 回答