class T { public static void test() throws Exception {
throw new Exception("Hello");
} @Override
protected void finalize() throws Throwable {
System.out.println(Thread.currentThread().getName()+" Finalize");
} public static void main(String[] args) {
T t = new T();
try {
test();
} catch (Exception e) {
System.out.println(Thread.currentThread().getName()+" Exception");//异常相关的,肯定是main线程
}
t=null;
// System.gc(); //垃圾回收相关的
}
}我是在想,能查看:“Reference Handler优先级:10” 吗?
期待高手
public class Test{
public static void main(String[] args) {
ThreadGroup group = Thread.currentThread().getThreadGroup().getParent();
group.list();
}
}
public class AllThread { public static Thread[] getAllThread() {
ThreadGroup root = Thread.currentThread().getThreadGroup();
ThreadGroup ttg = root;
while ((ttg = ttg.getParent()) != null) root = ttg;
Thread[] tlist = new Thread[(int)(root.activeCount() * 1.2)];
return java.util.Arrays.copyOf(tlist, root.enumerate(tlist, true));
} public static void main(String[] args) {
Thread[] ts = getAllThread();
for (Thread t : ts) {
System.out.println(t.getId() + ": " + t.getName() + " " + t.getPriority());
}
}}
输出:
2: Reference Handler 10
3: Finalizer 8
4: Signal Dispatcher 9
5: Attach Listener 5
1: main 5