How/when to close Streams and Handles

Skip to first unread message

Mihael Schmidt

Apr 20, 2022, 2:37:55 AM4/20/22
to jDBI
I am creating a rather large JSON ( > 180MB) from some database records. That works fine but consumes a lot of memory. I am now trying to get this in check with using java.util.Stream as a return value from my SQL Object interfaces.

I have a database service class and a web service endpoint class (JAX-RS). As I cannot close the Jdbi Handle when leaving the database service class method because the data from the stream has not been retrieved and processed yet what is a good way of closing the handle? Any good pattern/mechanism?

Thanks in advance.

Reply all
Reply to author
0 new messages