标题暗示我不知道我的程序中有三个线程?
我的建议是:
(1)主线程
(2)EDT(因为JButton)
(3)????
这是我的代码(非常简单):
package newProject;
import javax.swing.JButton;
public class MyExample {
public static void main(String[] args) {
System.out.println(Thread.activeCount() + " " + Thread.currentThread());
MyThread myExample = new MyThread();
System.out.println(Thread.activeCount() + " " + Thread.currentThread());
}
}
class MyThread {
JButton button=new JButton();
public MyThread() {
}
}
答案 0 :(得分:2)
线程的名称总是有用的。您可以通过以下名称列出所有主题:
import java.util.*;
public class ListThreads {
public static void main(String []args){
Set<Thread> threadSet = Thread.getAllStackTraces().keySet();
for (Thread t : threadSet) {
System.out.println (t.getName());
}
}
}
对我而言,它列出了:
编辑:threadSet行取自此处:Get a List of all Threads currently running in Java