我有一个线程数组列表,如果从 GUI 按下取消按钮,我想停止列表中的所有线程。有没有办法阻止所有这些线程?
List<Thread> threads = new ArrayList<>();
EncryptThread encryptThread = null;
for(int j=0;j<fileEncrytionList.size();j++){
encryptThread = new EncryptThread();
encryptThread.setFilePath(fileEncrytionList.get(j));
encryptThread.setOutPutFile(fileName);
Thread t = new Thread(encryptThread);
t.start();
threads.add(t);
}
if(cancel button pressed) // stop all threads from arraylist
Run Code Online (Sandbox Code Playgroud)