Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to make a daemon thread

 
santhosh.R gowda
Ranch Hand
Posts: 296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I want to write a code to make a daemon thread. That thread should be running in the background every time as and when the system started(Ex-jvm). And also this should execute particular method in the midnight.

regards
santosh
 
Rahul P Kumar
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
probably you need scheduler with this thread. making a thread daemon is easy. look into web.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the java.util.Timer and TimerTask classes - this sounds like a perfect application for them (and they can be made to run as background threads).
 
Vadivel Murugesan
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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) ・/b> 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:

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic