Question

I have a ThreadPoolExecutor that runs a few core and a certain max number of threads. The task that is run creates HornetQ (standalone) connections for each thread and keeps them alive while the thread is running. However, we cannot close them when the thread keepAliveTime expires and the thread dies. Is there a way clean up resources right before the thread dies?

One way out of this would be using a pooling solution for HornetQ connections.

Any suggestions are highly appreciated.

Was it helpful?

Solution

If you are using JDK 1.7, you could embed stuff on a closable interface, and it would be closed as soon as out of scope. We are working on implementing that on JMS 2, but meanwhile you could embed your own class delegating stuff. You will have to keep stuff referenced somewhere in your thread so it will only go out of scope when the thread is gone. (Thread local maybe?)

you need to use try (statement=statement.open()) {} and auto closeable would be called

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top