Thread.isAlive() should be used carefully in such a scenario. It would be fruitful if it is used before the completion of the normal thread. If the non-daemon has already ended, Thread.isAlive is bound to return false.
rebius hagrid wrote: Can we make the thread object call any method when the thread dies ???
Anything that happens in your thread, or in other words, anything your thread does is there written by you in the run() method or however you pragrammed it. Before run() ends, you can do a notificatoin.
But there are other better ways to make notifications, the link marked by Sebastian is really helpful
I know that I am going to catch flak for this, but... most of the time, this functionality won't be used. It is rare that an application will just have the user threads terminate, and use the daemon criteria to determine whether a JVM will exit.
Most of the time, the exit criteria is determine by a very specific event, which triggers a shutdown (saving resources, etc) and exit of the JVM (using System exit).
Interesting feature. Nice to know. But in most cases, not used...
I find daemon threads useful for background tasks that don't have any special cleanup needs. In other words, nobody gets bothered if the thread just goes away in the middle of doing something because the JVM quits, or the web app is stopped, or whatever. If those threads are daemons, they don't need to be stopped explicitly - so there's no need to keep track of them, or to add logic to terminate them gracefully.