이클립스에서 톰캣을 이용한 프로젝트를 WAR파일로 배포할 때 유의할 점 (메모리 누수)

가끔 톰캣 로그를 tail -f로 확인하다보면, WARNING 로그가 뜰 때가 있었습니다.
얼핏 memory leak… 어쩌고 저쩌고 이런 메시지들이 나왔는데, 별 오류는 없어서 신경을 안쓰고 있다가
오늘 갑자기 마지막 로그였던 다음의 내용들이 눈에 들어왔던 것이었습니다.

 

WARNING [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesJdbc The web application [something] registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister it when the web application was stopped. To prevent a memory leak, the JDBC Driver has been forcibly unregistered.
WARNING [ContainerBackgroundProcessor[StandardEngine[Catalina]]] org.apache.catalina.loader.WebappClassLoaderBase.clearReferencesThreads The web application [something] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:

The web application [ROOT] appears to have started a thread named [Abandoned connection cleanup thread] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread: 등등등…

 

위와 같은 오류 메시지를 확인한 뒤, 스택오버플로우를 열심히 뒤져보았습니다.

아니나 다를까, 좋은 답변이 있어 그 내용을 올려보도록 하겠습니다.

결론적으로, 이클립스에서 프로젝트를 WAR파일로 묶어 배포를 주로 하게 되는데, 이때 WAR파일의 Library에 들어있는 MySQL Connector / Driver 파일을 지우고, 이 라이브러리를 tomcat의 lib 디렉토리로 옮겨놓으라는 것이었습니다.

이유는 war 파일 내에 해당 Connector/Driver.jar 파일이 들어있는 경우, 하나의 프로젝트면 크게 상관이 없을지도 모르겠으나 여러 프로젝트를 webapps 아래에 war파일로 배포하게 되는 경우, 해당 커넥터/드라이버가 계속 생성이 될 것이라는 점이었습니다. 게다가 향후 JVM의 가비지컬렉터가 활성화 되더라도 MySQL에 들락날락거리는 그 접속 객체를 삭제할 수가 없게 될 수도 있어 결국 메모리를 고갈시킬 수 있는 문제가 있다는 것이었습니다.

그러니, war 파일에 해당 연결/드라이버 라이브러리를 넣지 말고, 톰캣이 설치된 디렉토리 아래의 lib 디렉토리에 mysql-connector-java-x.x.xx.jar 파일을 이동시키라는 이야기였습니다.

혹시라도 이런 로그를 만나시게 된다면, 위와 같은 방법을 통해 문제를 해결하시길 바라며 이만 포스팅을 마치겠습니다!

You may also like...

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.