小编tyb*_*900的帖子

停止线程列表

我有一个线程数组列表,如果从 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)

java swing multithreading java-threads

4
推荐指数
1
解决办法
65
查看次数

标签 统计

java ×1

java-threads ×1

multithreading ×1

swing ×1