Sponsered Links
Categories
Sponsered Links

Java Daemon Thread Example

 

 This is a simple Java Daemon Thread Example.

 import java.io.*;

import java.util.*;

class MyDaemon implements Runnable {
Thread thread;

MyDaemon() {
thread = new Thread(this);
thread.setDaemon(true);
thread.start();
}

public boolean isDaemon(){
return thread.isDaemon();
}

public void run() {
try {
while(true) {
System.out.print(".");
Thread.sleep(100);
}
} catch(Exception exc) {
System.out.println("MyDaemon thread interrupting");
}
}
}

public class DaemonThreadExample {
public static void main(String args[]) throws Exception{
MyDaemon dt = new MyDaemon();
if(dt.isDaemon())
System.out.println("Daemon thread start");
Thread.sleep(10000);
System.out.println("\nMain thread end");
}
}

 
 
Sponsered Links
Latest Updates
 
All Content of this site is for learning only. We do not warrant the correctness of its content. The risk from using it lies entirely with the user. While using this site, you agree to have read and accepted our terms of use and privacy policy.
Copyright © 2009 JSPSERVLETTUTORIAL.INFO All Right Reserved