gpt4 book ai didi

java - 如何从线程组中删除线程

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

每次我创建新线程时,它都会被添加到主线程组中,即使我将线程清零,它仍然存在于主线程组中,导致内存泄漏。请帮忙

已更新

public void surfaceDestroyed(SurfaceHolder holder) {
Log.d("mThread", "Surface Destroyed Called");
getHolder().removeCallback(this);
boolean retry = true;
_thread.setRunning(false);
while (retry) {
try {
Log.d("mThread", "b4 Interrupted");
_thread.interrupt();
Log.d("mThread", "b4 thread group Interrupted");
_thread.getThreadGroup().interrupt();
Log.d("mThread", "b4 join");
_thread.join();
retry = false;
} catch (InterruptedException e) {
Log.d("mThread", "Interrupted");
Thread.currentThread().interrupt();
_thread.getThreadGroup().list();
_thread = null;//======>here nulling thread
break;
}
}
}

最佳答案

问题不在于加入了线程组。已终止的线程将始终(最终)从线程组中删除。

如果应用程序正在泄漏内存,那么您的代码中就有错误。你找错人了。

关于java - 如何从线程组中删除线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6304985/

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