Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Daemon Threads 
 

This section describes about the daemon threads in java.

 

Daemon Threads

                         

In Java, any thread can be a Daemon thread. Daemon threads are like a service providers for other threads or objects running in the same process as the daemon thread. Daemon threads are used for background supporting tasks and are only needed while normal threads are executing. If normal threads are not running and remaining threads are daemon threads then the interpreter exits.

       setDaemon(true/false) – This method is used to specify that a thread is daemon thread.

       public boolean isDaemon() – This method is used to determine the thread is daemon thread or not.

The following program demonstrates the Daemon Thread:

public class DaemonThread extends Thread {
  public void run() {
    System.out.println("Entering run method");

    try {
      System.out.println("In run Method: currentThread() is"
          + Thread.currentThread());

      while (true) {
        try {
          Thread.sleep(500);
        catch (InterruptedException x) {
        }

        System.out.println("In run method: woke up again");
      }
    finally {
      System.out.println("Leaving run Method");
    }
  }
  public static void main(String[] args) {
    System.out.println("Entering main Method");

    DaemonThread t = new DaemonThread();
    t.setDaemon(true);
    t.start();

    try {
      Thread.sleep(3000);
    catch (InterruptedException x) {
    }

    System.out.println("Leaving main method");
  }

}

Output of this program is:

C:\j2se6\thread>javac DaemonThread.java

C:\j2se6\thread>java DaemonThread
Entering main Method
Entering run method
In run Method: currentThread() isThread[Thread-0,5,main]
In run method: woke up again
In run method: woke up again
In run method: woke up again
In run method: woke up again
In run method: woke up again
In run method: woke up again
Leaving main method

C:\j2se6\thread>

Download this example

                         

» View all related tutorials
Related Tags: java c class interface object io read thread int this creation extend run lan ext e il section can im

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

3 comments so far (
post your own) View All Comments Latest 10 Comments:

Please run the EJB on Ecllipse IDE.bcz i have problem in it.

Posted by Shani Kumar Gupta on Wednesday, 06.4.08 @ 16:04pm | #62078

please show best example for Expression Language program and jsp usebean programin jsp concepts

Posted by kamala on Tuesday, 04.1.08 @ 17:30pm | #55042

hi.. i want free online books for core java ( pdf or doc) format,where can i have these books ?

thanks in Regards
Karthik

Posted by karthikeyan on Monday, 03.24.08 @ 16:14pm | #54146

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.