日期:2014-05-20 浏览次数:20978 次
public 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(); //垃圾回收相关的
}
}
------解决方案--------------------
2楼该多看点书了,可以参考一下java虚拟机规范中的异常处理介绍,看看jvm怎么提供专门的指令来支持异常处理的。
不知道你的确定结论是如何得到的。
------解决方案--------------------
个人觉得应该是同一线程中的...看了Tinking in java 也没提到异常处理是单独的一个线程
------解决方案--------------------
是有很多呀!但是只是说所以的java应用程序是从主线程main启动的而已。
------解决方案--------------------
用netbeans调试了一下,发现启动的System下的线程有
main
Reference Handler
Finalizer
Signal Dispatcher
Attache Listener
一共五个。
以前的帖子也提到过,只是自己水平太菜,没有关注。
------解决方案--------------------
使用到窗口程序的话还有AWT-Windows、AWT-EventQueue-0等很多线程被启动。
------解决方案--------------------
在4楼的代码中可以直接得到Finalizer线程的信息。
通过线程组也可以直接活动所有线程的信息,不过没有多少实际的意义。
------解决方案--------------------
额 用线程组查看的线程信息
public static void main(String[] args) {
ThreadGroup threadGroup= Thread.currentThread().getThreadGroup().getParent();
Thread[] list=new Thread [threadGroup.activeCount()];
threadGroup.enumerate(list,true);
for (Thread thread : list) {
System.out.println(thread.getName()+"优先级:"+thread.getPriority());
}
}