Write a Java program to demonstrate the concept of daemon threads

Write a Java program to demonstrate the concept of daemon threads  


program :

 public class DaemonThread extends Thread 

{

 int i;

 public void run()

 {

 for(i=0;i<5;i++); 

{

 System.out.println(this.getName()+" "+i); 

}

 public static void main(String[] args)

 { 

DaemonThread d=new DaemonThread(); 

DaemonThread d1=new DaemonThread(); 

d.setName("\nDAEMON THREAD"); 

d1.setName("NORMAL THREAD"); 

d.setPriority(Thread.MIN_PRIORITY); 

d.start(); 

d1.start(); 

}


Output :

NORMAL THREAD 5


DAEMON THREAD 5


Or

DAEMON THREAD 5

NORMAL THREAD 5


daemon threads are low-priority threads whose only role is to provide services to user threads.

Daemon threads are useful for background supporting tasks such as garbage collection, releasing memory of unused objects and removing unwanted entries from the cache.


Comments

Popular posts from this blog

Control Statements:Selection statement ,Iteration statement and Jump statement in Java

Abstract classes and Abstract methods in Java with Examples rcub.

Applets - Inheritance hierarchy for applets, differences between applets and applications, life cycle of an applet, passing parameters to applets, applet security issues.