What you need is SXSSF (Streaming Usermodel API).
SXSSF (package: org.apache.poi.xssf.streaming) is an API-compatible streaming extension of XSSF to be used when very large spreadsheets have to be produced, and heap space is limited.
There is an example on that page too: you need to substitute XSSFWorkbook
with SXSSFWorkbook
.