问:在父线程中New了一个子线程,想在停止父线程时也停止子线程,应该怎么做?

答:
从某种程度上讲,做不到。   
  不管是父线程还是子线程,这只不过是在运行时谁建了谁时用的,一旦所谓的字线程被启动,这两个线程是没有先后贵贱区分的。   
  任何线程是没有办法把另外一个线程终止的。   
  如果你一定想你说的那样是线的话,下面是唯一个可行方案。在"父线程"建立“子线程”时,把“父线程”的instance传过去,在“子线程”里,不停的check"父线程"是否还存活,如果否,停止。   
  相反的,如果"父线程"需要在"子线程"终了时结束,在"父线程"建立“子线程”时,留住“子线程”的instance然后keep   checking   whether   it's   still   alive.
================================================================================
只有在所有非守护进程都停止的情况下,jvm才退出。main线程停止jvm也不一定退出:
  public class TestMitiThread {
    public static void main(String[] rags) {
        System.out.println(Thread.currentThread().getName() + " 线程运行开始!");
        new MitiSay("A").start();
        new MitiSay("B").start();
        System.out.println(Thread.currentThread().getName() + " 线程运行结束!");
    }
}
 
class MitiSay extends Thread {
    public MitiSay(String threadName) {
        super(threadName);
    }
 
    public void run() {
        System.out.println(getName() + " 线程运行开始!");
        for (int i = 0; i < 10; i++) {
            System.out.println(i + " " + getName());
            try {
                sleep((int) Math.random() * 10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println(getName() + " 线程运行结束!");
    }
}
 
运行结果:
 
main 线程运行开始!
main 线程运行结束!
A 线程运行开始!
0 A
1 A
B 线程运行开始!
2 A
0 B
3 A
4 A
1 B
5 A
6 A
7 A
8 A
9 A
A 线程运行结束!
2 B
3 B
4 B
5 B
6 B
7 B
8 B
9 B
B 线程运行结束!
===========================================
novice
expertise
inception
rudiment
prudent
... is the way to go
=========================================
sas:
sas variable must not be more than 8 characers
use character variables sparingly--page 4