复制代码
- //:Daemons.java
- //Daemonicbehavior
- importjava.io.*;
- classDaemonextendsThread{
- privatestaticfinalintSIZE=10;
- privateThread[]t=newThread[SIZE];
- publicDaemon(){
- setDaemon(true);
- start();
- }
- publicvoidrun(){
- for(inti=0;i<SIZE;i++)
- t[i]=newDaemonSpawn(i);
- for(inti=0;i<SIZE;i++)
- System.out.println(
- "t["+i+"].isDaemon()="
- +t[i].isDaemon());
- while(true)
- yield();
- }
- }
- classDaemonSpawnextendsThread{
- publicDaemonSpawn(inti){
- System.out.println(
- "DaemonSpawn"+i+"started");
- start();
- }
- publicvoidrun(){
- while(true)
- yield();
- }
- }
- publicclassDaemons{
- publicstaticvoidmain(String[]args){
- Threadd=newDaemon();
- System.out.println(
- "d.isDaemon()="+d.isDaemon());
- //Allowthedaemonthreadstofinish
- //theirstartupprocesses:
- BufferedReaderstdin=
- newBufferedReader(
- newInputStreamReader(System.in));
- System.out.println("WaitingforCR");
- try{
- stdin.readLine();
- }catch(IOExceptione){}
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |