2012-06-01 2 views
0

jtds 연결 드라이버를 사용하여 매우 새롭습니다. 2500 개의 큰 xml을 읽고 SQL 쿼리를 작성하고 SQL 서버에 대해 실행하는 애플리케이션을 작성했습니다. 나는 특정 양의 xml에 이르면 내 프로그램의 메모리가 부족하다는 것을 알았다. 메모리 분석기를 사용하여 Eclipse에서 phd 덤프 파일을 검사 한 결과 net.sourceforge.jtds.jdbc.cache.SimpleLRUCache가 많은 메모리를 보유하고있는 것으로 나타났습니다. SQL 서버에 한 번 연결하고 모든 쿼리를 플러시 할 때까지 연결을 유지합니다. 아래는 서버에 대한 쿼리를 실행하기위한 코드입니다. net.sourceforge.jtds.jdbc.cache.SimpleLRUCache 클래스에 대한 핸들을 얻는 방법을 모르겠지만 캐시를 지울 수있는 명확한 방법이 있기 때문입니다. 다시 jtds 드라이버에 대해 잘 알지 못합니다. 누구든지이 문제를 해결하는 데 도움이 될 수 있습니까?net.sourceforge.jtds.jdbc.cache.SimpleLRUCache는 메모리 누수를 야기합니다.

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; 
} 

답변

1

FAQ는 JDBC URL에서 maxStatements에 대한 낮은 값을 설정하여 명령문 캐시의 크기를 변경하는 방법에 대해 설명합니다. 매우 큰 명령문을 작성하는 경우,이 한계를 기본값 인 500보다 훨씬 낮게 설정할 수 있습니다. 또한 다른 메모리 설정 중 일부를 볼 수도 있습니다.

+0

존 감사합니다. 그것은 내 문제를 해결했다. –

관련 문제