【发布时间】:2015-10-21 23:49:21
【问题描述】:
我的 Tomcat webapp 向 SVN 查询两个时间点之间的提交:
final SVNURL url = SVNURL.parseURIEncoded("svn+ssh://xxxx/xxxx/xxxx");
SVNSSHAuthentication sshCredentials = SVNSSHAuthentication.newInstance(
Constants.SVN_USERNAME,
Constants.PRIVATE_KEY,
Constants.PRIVATE_KEY_PASS_PHRASE,
Constants.SVN_PORT,
Constants.ALLOW_CREDENTIALS_TO_BE_STORED,
url,
Constants.CREDENTIAL_IS_NOT_PARTIAL);
ISVNAuthenticationManager authManager = new BasicAuthenticationManager(new SVNAuthentication[] { sshCredentials });
SvnOperationFactory svnOperationFactory = new SvnOperationFactory();
try {
svnOperationFactory.setAuthenticationManager(authManager);
final SvnLog log = svnOperationFactory.createLog();
log.addRange(SvnRevisionRange.create(SVNRevision.create(new Date(1444612639000l)), SVNRevision.create(new Date(1444737236000l))));
log.setDiscoverChangedPaths(true);
log.setLimit(100l);
log.setReceiver(new ISvnObjectReceiver<SVNLogEntry>() {
@Override
public void receive(SvnTarget target, SVNLogEntry logEntry) throws SVNException {
System.out.println(logEntry);
}
});
log.setSingleTarget(SvnTarget.fromURL(url));
log.run();
}
catch (SVNException e) {
throw e;
} finally {
svnOperationFactory.dispose();
}
问题:每次重新加载或重新部署webapp时,有几个线程没有被杀死,导致Permanent Generation中的类重复:
这些是每次调用log.run() 时创建的线程。您会看到有两个组 - 第一组属于 webapp 的前一个实例 - 它已经停止 - 由于某种原因,它们没有与 webapp 一起被杀死。
线程 6 和线程 11 的堆栈跟踪:
Thread dump at 5:11.060.359
* Thread group "main":
Thread "Thread-6":
at java.net.SocketInputStream.socketRead0(java.io.FileDescriptor, byte[ ], int, int, int)
at java.net.SocketInputStream.read(byte[ ], int, int, int)
at java.net.SocketInputStream.read(byte[ ], int, int)
at com.trilead.ssh2.crypto.cipher.CipherInputStream.fill_buffer()
at com.trilead.ssh2.crypto.cipher.CipherInputStream.internal_read(byte[ ], int, int)
at com.trilead.ssh2.crypto.cipher.CipherInputStream.getBlock()
at com.trilead.ssh2.crypto.cipher.CipherInputStream.read(byte[ ], int, int)
at com.trilead.ssh2.transport.TransportConnection.receiveMessage(byte[ ], int, int)
at com.trilead.ssh2.transport.TransportManager.receiveLoop()
at com.trilead.ssh2.transport.TransportManager$1.run()
at java.lang.Thread.run()
如果我注释掉log.run(),则不会创建线程,因此不会泄漏任何资源。所以问题是因为log.run() - 当webapp被杀死时,线程没有被杀死。
代码末尾的svnOperationFactory.dispose(); 似乎没有处理任何内容。
有什么想法吗?
【问题讨论】:
标签: java tomcat memory-leaks svnkit