Hello everyone,


I have a very important thread in my application and I do not want it to be terminated accidently, or in other words, if it is terminated for some reason (for example, be terminated by some unhandled Runtime exceptions), I want it to restart automatically.

I am wondering whether Java has build-in approach to implement this goal. If Java does not have build-in approach to implement this, I am wondering where can I find similar sample source codes or tutorials?


regards,
George

Well, if the JVM dies any thread in it dies as well so you can't have a thread that never dies at all.

Other than that, you can track whether your thread is alive of course.
Thread has a method for that called isAlive() which returns true if the thread is not dead (but has been started).
You can of course NOT restart a dead thread, so if it dies you'll have to create a new thread for it and start that.

I've found good threading tutorials very hard to find. I'm also still looking for a good threading book, the one I did get (Taming Java Threads) is probably the worst book on programming I've ever had the displeasure of reading and is the first programming book I ever tossed into the trash that wasn't completely outdated.

Thanks jwenting,

Well, if the JVM dies any thread in it dies as well so you can't have a thread that never dies at all.

Other than that, you can track whether your thread is alive of course.
Thread has a method for that called isAlive() which returns true if the thread is not dead (but has been started).
You can of course NOT restart a dead thread, so if it dies you'll have to create a new thread for it and start that.

I've found good threading tutorials very hard to find. I'm also still looking for a good threading book, the one I did get (Taming Java Threads) is probably the worst book on programming I've ever had the displeasure of reading and is the first programming book I ever tossed into the trash that wasn't completely outdated.

Both your reply and your advice are very helpful.


regards,
George

Thanks for all the people who helped me on this thread.

Thanks jwenting,


Both your reply and your advice are very helpful.


regards,
George

regards,
George

This article has been dead for over six months. Start a new discussion instead.