I'm using Spring Boot
with RabbitMQ
. In some cases my consumer threads (SimpleMessageListenerContainer
) get aborted because of StackOverflowError
. I was thinking of catching these kind of errors in order to save the threads and not having to restart my application every time this happens.
- Is a thread that went through that error in a state that can keep working or should I let it die?
- If I should let it die, how can I replenish the pool thread used by
org.springframework.amqp.rabbit
?
I know that in general we shouldn't catch Error
throwables, but I want to know what would happen in this particular case if I did.
Update
In the end I just performed the actions that would cause such a behaviour in a separate thread using Future
and masked (catch and rethrow) any throwable as a RuntimeException
. This way I could handle the exception in my consumer thread that remained clean. Not the most performant way of dealing with this, but it works great so far and performance has not been an issue.