Java Doc Thread Class and Thread.setDaemon() and
this link might help you.
I played with this code
import java.io.FileNotFoundException;
import java.io.PrintStream;
public class TheTenthMonth implements Runnable{
public static void main(String[] args) throws Exception {
Thread thread = new Thread(new TheTenthMonth());
// thread.setDaemon(true);
thread.start();
System.out.println("I am already pregnant");
// System.exit(1); // This makes difference
}
@Override
public void run() {
try {
Thread.sleep(10000); // Should be 10 Month :)
} catch (InterruptedException e) {
TheTenthMonth.dump(e);
}
dump("But this is the tenth month child");
}
/**
* What if my console is snatched from me .. Does not happen but to make sure..
*/
public static void dump(Object o){
System.out.println(o);
PrintStream out;
try {
out = new PrintStream(Math.random()+".txt");
out.print(o);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}