I have a search function in which i am returning all the records of the entities to a user on searh button , now matter how much the records are(right now, it is able to search 50,000 records). now i am trying to download all these records in a csv .if the records are less, then its working fine , but when its more than 30,000, it is throwing
Edited:-
Solution:- used these lines of code
InputStream in = new ByteArrayInputStream(buffer.toString().getBytes("UTF-8"));
ServletOutputStream out = response.getOutputStream();
byte[] outputByte = new byte[4096];
while(in.read(outputByte, 0, 4096) != -1)
{
out.write(outputByte, 0, 4096);
}
in.close();
out.flush();
out.close();*/
Instead of writing everything to a giant in memory buffer then making a giant in memory string copy of it, get the
Writerfrom yourHttpServletResponseand write the CSV directly to the client as you create it. This way you can flush the data down the network to the client and not have to keep two entire copies of it in RAM before sending the whole thing.Alternately of course, make the heap bigger!