We have a piece of code for reading from queue
while(true){ try { message = readMessageFromQueue(); processMesage(message); //Writes into DB and some other operation }catch(Exception e) { log the exception } } Now there are ten threads which are spawned using executor service with the aim of running forever. However we have noticed after sometime we deploy(it can be 10-15 days or month) the number of thread is getting reduced(Write per second is also decreasing because of that).
The question is should we catch Error or only exception in the code which we want to run forever like this and is catching Exception can cause this problem ?