gpt4 book ai didi

java - SVNKit 内存泄漏 : SVNLog. run() 创建永远不会被杀死的线程

转载 作者:行者123 更新时间:2023-11-28 22:02:03 25 4
gpt4 key购买 nike

我的 Tomcat 网络应用程序查询 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中有重复的类: enter image description here

这些是每次调用 log.run() 时创建的线程。你看到有两个组——第一组属于 webapp 的前一个实例——它已经被停止了——出于某种原因,它们没有与 webapp 一起被杀死。 enter image description here

线程 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(); 似乎没有处理任何东西。

有什么想法吗?

最佳答案

根据我的经验,第三方软件的泄漏确实取决于版本。您的问题没有说明您使用的是哪个版本的 SVNKit。因此,作为第一个回应,我会问您是否使用最新版本的 SVNKit。我一直在研究一些 SVNKit 的候选内存泄漏,包括:

  1. No dispose called on SVNClients
  2. Orphaned threads with svn+ssh connections

还有其他一些。但是,它们似乎都适用于旧版本的 SVNKit,因此如果可能的话,我会先尝试升级。

关于java - SVNKit 内存泄漏 : SVNLog. run() 创建永远不会被杀死的线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33271192/

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