How to make a thread never be terminated?

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2004
Posts: 189
Reputation: George2 is an unknown quantity at this point 
Solved Threads: 0
George2 George2 is offline Offline
Junior Poster

How to make a thread never be terminated?

 
0
  #1
Dec 15th, 2004
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,143
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: How to make a thread never be terminated?

 
0
  #2
Dec 16th, 2004
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.
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 189
Reputation: George2 is an unknown quantity at this point 
Solved Threads: 0
George2 George2 is offline Offline
Junior Poster

Re: How to make a thread never be terminated?

 
0
  #3
Dec 20th, 2004
Thanks jwenting,


Originally Posted by 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
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 189
Reputation: George2 is an unknown quantity at this point 
Solved Threads: 0
George2 George2 is offline Offline
Junior Poster

Re: How to make a thread never be terminated?

 
0
  #4
Dec 23rd, 2004
Thanks for all the people who helped me on this thread.


Originally Posted by George2
Thanks jwenting,




Both your reply and your advice are very helpful.


regards,
George

regards,
George
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC