Hi,
could anyone please tell me what is a daemon
thread and how to recognize it?
The example given below contains daemon thread.Can anyone elaborate on this
and explain a bit clearly.
And when do we use daemon thread?
class A extends Thread {
private Object obj;
public A(Object obj) {this.obj = obj;}
public void run() {
try {
synchronized (obj) {obj.wait();}
} catch (InterruptedException ie) {}
System.out.print(Thread.currentThread().getName());
}}
class B {
private void m1() {
for (int i = 0; i < 10; i++) {
A t1 = new A(this);
t1.setName(String.valueOf(i)); t1.setDaemon(true); t1.start();
}
synchronized (this) {notifyAll();}
}
public static void main(
String[] args) {new B().m1();}
}