944,125 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 4178
  • Java RSS
Dec 15th, 2004
0

How to make a thread never be terminated?

Expand Post »
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
Similar Threads
Reputation Points: 11
Solved Threads: 0
Junior Poster
George2 is offline Offline
189 posts
since Nov 2004
Dec 16th, 2004
0

Re: How to make a thread never be terminated?

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Dec 20th, 2004
0

Re: How to make a thread never be terminated?

Thanks jwenting,


Quote 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
Reputation Points: 11
Solved Threads: 0
Junior Poster
George2 is offline Offline
189 posts
since Nov 2004
Dec 23rd, 2004
0

Re: How to make a thread never be terminated?

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


Quote originally posted by George2 ...
Thanks jwenting,




Both your reply and your advice are very helpful.


regards,
George

regards,
George
Reputation Points: 11
Solved Threads: 0
Junior Poster
George2 is offline Offline
189 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: How to load binary content of a .class file?
Next Thread in Java Forum Timeline: JTable not calling getValueAt - any ideas?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC