我在 java android 平台上工作。我正在从主线程创建一个子线程。我想停止子线程作为我的要求。我的子线程有简单的函数,没有任何循环。我想随时终止子线程并释放它正在使用的资源。我搜索它并找到了 inturrupt() 函数。我的线程是:
public class childThread implements Runnable{
public void run() {
firstFunction();
secondFunction();
}
}
Run Code Online (Sandbox Code Playgroud)
主线程有此代码在线程上方启动:
Thread tChild;
tChild = new Thread(new childThread(), "Child Thread");
tChild.start();
Run Code Online (Sandbox Code Playgroud)
我的run()函数正在调用这样的函数。我interrupt()在这如何使用?请告诉我任何其他杀死子线程并释放其资源的方法。