1: thread t = new thread() {
3: system.out.println("im a 【程序编程相关:关于runtime exception和】 2: public void run() { 【推荐阅读:我对构架MVC的理解】 4: } 【扩展信息:JVM结构基础(一)】 man of wealth and taste..."); 5: }; 6: 7: t.setdaemon(true); 8: t.start();the second technique for creating a daemon thread is based on an often overlooked feature of javas threading behavior. if a thread creates a new thread and doesnt call setdaemon() on the new thread before its started, the new thread will inherit the "daemon-status" of the creating thread. for example, unless setdaemon(false) is called, all threads created by daemon threads will also be daemon threads; likewise, unless setdeamon(true) is called, all threads created by user threads will be user threads.
the program in listing 2 illustrates this behavior. the program creates a thread, t1, whose only purpose in life is to create another thread, t2, whose destiny is to print a greeting, "pleased to meet you," for all eternity. if you run this code youll see that even though the main thread ends, t2 goes on forever, printing its tempting message. this behavior is due to the fact that t2 inherited its user... 下一页