Replies: 4 comments
-
Well, the ByteArrayOutputStream is kept entirely in memory, so writing to a FileOutputStream or a PipedOutputstream might be an option ? Depends a bit on the application ... Or eg. Apache Commons-IO DeferredFileOutputStream (you may have to delete the file separately...) PS you might also move the connection part to a try-with-resources block, which would remove the need for a
|
Beta Was this translation helpful? Give feedback.
-
Well the application is a REST spring boot application so would like to return this result back over http ... ( converting the ByteArrayOutputStream to a String was as well problematic). |
Beta Was this translation helpful? Give feedback.
-
Part of the problem is the ByteArrayOutputStream copy / resize behavior. Increasing the java heap space of the JVM might also help (-Xmx) But that still may not make that much of a difference for really big result sets... Not a Spring expert, but wouldn't it be possible to open an OutputStream outside this method, and pass it in as a parameter, so the results are written directly to the HTTP response, instead of writing / copying things ? https://www.logicbig.com/how-to/code-snippets/jcode-spring-mvc-streamingresponsebody.html
|
Beta Was this translation helpful? Give feedback.
-
Maybe you want to look into spring StreamingResponseBody or grabbing the output stream from HttpServletResponse. |
Beta Was this translation helpful? Give feedback.
-
Current Behavior
We are trying to write results back using a SPARQLResultsJSONWriter but we get an OutOfMemoryError on the given output stream. The code snippet below shows how we initiate the writer and how the result is returned back:
The stack trace is the following:
P.S: The expected result is huge and we believe that the output stream is getting bigger and bigger up until it throws this error, so is there a way to use some kind of buffering to avoid this problem?
Expected Behavior
Return back the result in json format
Steps To Reproduce
No response
Version
3.4.6
Are you interested in contributing a solution yourself?
No response
Anything else?
No response
Beta Was this translation helpful? Give feedback.
All reactions