本帖最后由 柏占肖 于 2012-10-10 08:52 编辑
- public class CatchThreadTerminate {
- public static void main(String[] args) {
- final Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- for (int i = 0; i <= 100; i++) {
- System.out.println(i);
- }
- }
- });
- thread.start();// 启动thread线程
- new Thread(new Runnable() {
- @Override
- public void run() {
- while (true) {
- if (Thread.State.TERMINATED == thread.getState()) {
- /* 如果thread线程死亡则打印下面这条语句 */
- System.out.println("线程死亡");
- break;// 已经捕获到thread的死亡,结束监听
- }
- }
- }
- }).start();// 启动一个线程来监听thread线程是否是亡
- }
- }
复制代码 呵呵……自己看了API后想到的这么一个办法,非标答,纯属交流
|