HomeDigital EditionSys-Con RadioSearch Java Cd
Advanced Java AWT Book Reviews/Excerpts Client Server Corba Editorials Embedded Java Enterprise Java IDE's Industry Watch Integration Interviews Java Applet Java & Databases Java & Web Services Java Fundamentals Java Native Interface Java Servlets Java Beans J2ME Libraries .NET Object Orientation Observations/IMHO Product Reviews Scalability & Performance Security Server Side Source Code Straight Talking Swing Threads Using Java with others Wireless XML
 

"Beware the Daemons"
Volume: 5 Issue: 3, p.34

	

Listing 1:

 1: import java.awt.*;
 2: import java.awt.event.*;
 3:
 4: public class Tester {
 5:    public static void     
       main(String[] args) {
 6:       Frame f = new Frame();
 7:
 8:       f.addWindowListener(new 
          WindowAdapter() {
 9:          public void windowClos-
             ing(WindowEvent evt) {
10:             System.exit(0);
11:          }
12:       });
13:
14:       f.setBounds(30, 30, 400, 
          400);
15:       f.setVisible(true);
16:    }
17: }



Listing 2:

 1: public class Tester {
 2:    public static void  
       main(String[] args) {
 3:       Thread t1 = new Thread() {
 4:          public void run() {
 5:             // Fire off a new                  
            thread.
 6:             Thread t2 = new 
                Thread() {
 7:                public void run()  
                   {
 8:                   while(true)
 9: System.out.println("Pleased to 
    meet you.");
10:                }
11:             }; // end of t2
12:
13:             t2.start();
14:          }
15:       }; // end of t1
17:
18:       // t1.setDaemon(true);
19:       t1.start();
20:
21:       for(int i = 0; i < 50; 
          ++i)
22: System.out.println("Hope you 
    guess my name.");
23:
24:       System.out.println("Main 
          thread is about to end.");
25:    } // main()
26: } // Tester


Listing 3:

 1: import java.awt.*;
 2:
 3: public class Tester {
 4:    public static void 
       main(String[] args) {
 5:       Thread t1 = new Thread() {
 6:          public void run() {
 7:             Frame f = new 
                Frame();
 8:             f.setBounds(30, 30, 
                400, 400);
 9:             f.setVisible(true);
10:          }
11:       }; // end of t1
12:
13:       t1.setDaemon(true);
14:       t1.start();
15:
16:       try { Thread.sleep(5000); 
          }
17:       catch(InterruptedException 
          e) {}
18:    } // main()
19: } // Tester




 

All Rights Reserved
Copyright ©  2004 SYS-CON Media, Inc.
  E-mail: [email protected]

Java and Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the United States and other countries. SYS-CON Publications, Inc. is independent of Sun Microsystems, Inc.