Thursday, December 2, 2010

Daemon Threads

Daemon Threads are generally taken to consideration in Application development when there is some task to be done, however of not much priority. Say like U have an GUI application whose task is to get User Name & Password & validate it....however, U would like to put up few ads/JPGS on the screen .... In such a case we will associating a main thread to validate UID/PWD & daemon threads to show or change the ads.... In the above example there's no use of the GUI with just ads & without the UID/PWD screen & validator. So JVM can make the daemon thread exit. Generally Daemon threads are used when there are some not-so-important task to done along with the main task.

Timer scheduler = new Timer(isDaemon); //for creating domean threads isDaemon = true

scheduler.cancel(); //cancel the assigned tasks
scheduler.purge(); //remove the tasks in queue so that it can be garbage collected.

No comments:

Post a Comment