org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.OutOfMemoryError: Direct buffer memory
org.springframework.web.util.NestedServletException:Handler dispatch failed;
nested exception is java.lang.OutOfMemoryError: Direct buffer memory
파일을 읽어 ByteArray 형식으로 리턴 할때 문제가 발생 하였다.
내가 코드를 사용한 곳은 주로 첨부파일 다운로드나, 특정 경로의 이미지 파일을 mime type 에 맞게 내려 주는 부분 이라
파일 다운로드도 안되고 이미지도 디스플레이가 되지 않았다.
1. Files.readAllBytes() 사용시 주로 발생.
2. 명령행 옵션으로 -XX:MaxDirectMemorySize=500m 과 같이 주어도 어느 정도 시간이 지나면 다시 발생.
3. apache.commons.io 의 FileUtils.readFileToByteArray() 나 IOUtils.toByteArray() 사용을 권장.
4. 클라이언트에서 파일 다운로드 시간 단축 및 서버 콘솔에서 에러 메세지 발생하지 않음.
자세한 설명은 아래 참고 할 것
참고 : homoefficio.github.io/2020/08/10/Java-NIO-FileChannel-%EA%B3%BC-DirectByteBuffer/
Java NIO FileChannel 과 DirectByteBuffer
Java 4에서 도입된 NIO 덕분에 FileChannel과 ByteBuffer를 이용해서 File I/O 를 수행할 수 있게 됐다. 그림 출처: https://www.happycoders.eu/java/filechannel-bytebuffer-memory-mapped-file-locks/ NIO의 장점은 https://homoefficio.gi
homoefficio.github.io