I have an app that starts 10 threads. Each thread does it's work and waits (using the producer consumer model). So when more work comes along, one of the threads is unblocked and it does the work.
A colleague at work insists I should write some code that monitors the threads "just in case" they freeze/do not respond or die.
So far in my testing, they work fine and close down correctly.
My question is "should I put code in to do this"? If so, "how do I monitor a thread and check it's status"?
Thanks. JD
It really depends on the situation. First of all, you should focus on correctness so that it doesn't freeze or die but if you need more reliability, you should first think about how you can gracefully recover from such a situation. You should think about why it might freeze or die and if it did, now what you can do. If you can't do anything good that reliably recovers from such a situation, you shouldn't even try. If can do it without making the situation worse, then you can go and try doing so.
Obviously, if you made such a choice, you have to be careful not to mess things up and introduce some bugs that actually make the bad stuff happen yourself.
Ideally no, your threads should be able to finish properly. Monitoring them is not worth the complexity and processing time. If you do it correctly you won't need monitoring.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With