| | |
How to make a thread never be terminated?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
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
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.
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.
•
•
Join Date: Nov 2004
Posts: 189
Reputation:
Solved Threads: 0
Thanks jwenting,
Both your reply and your advice are very helpful.
regards,
George
•
•
•
•
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.
regards,
George
![]() |
Similar Threads
- I can't make a new thread in Assembly forum (DaniWeb Community Feedback)
- Send data on a serial port (C++)
- Lets Make This Thread as an Information About Alexa And The Pr Thing for everybody (Search Engine Optimization)
- Help need with Socket, Thread, and BufferedReader (Java)
- Question about join of thread. (Java)
Other Threads in the Java Forum
- Previous Thread: GUI Window - Exit Button?
- Next Thread: JTable not calling getValueAt - any ideas?
| Thread Tools | Search this Thread |
Tag cloud for Java
affinetransform android api append apple applet application arguments array arrays automation bi binary bluetooth businessintelligence busy_handler(null) chat class classes client code component database draw eclipse encryption equation error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer intersect j2me java javaexcel javaprojects jmf jni jpanel julia linked linux list loop main map method methods mobile netbeans newbie number open-source oracle oriented panel print problem program programming project qt recursion reference replaysolutions repositories return robot scanner screen scrollbar se server set singleton size sms socket sort sql string swing test threads time tree utility windows xor






