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.