I use ByteBuffersand FileChannelswrite binary data to a file. When you do this for large files or sequentially for multiple files, I get an exception OutOfMemoryError. I read elsewhere that use ByteBufferswith NIO is impaired and should be avoided. Have any of you already encountered such a problem and found a solution for efficiently saving large amounts of binary data in a file in java?
ByteBuffers
FileChannels
OutOfMemoryError
Is jvm option possible -XX:MaxDirectMemorySize?
-XX:MaxDirectMemorySize
, ByteBuffer, . ByteBuffer, , FileChannel. reset ByteBuffer , .
Java Mapped Byte Buffers, " ". , "" . / -, , . NIO, Java, - .
, , :
Kirk Pepperdine ( Java) - www.JavaPerformanceTuning.com, MBB: NIO
( , , , ), ;-)
, . java.io.FileOutputStream (.. DataOutputStream, ObjectOutputStream) , , serializeable . .
java.io.FileOutputStream
DataOutputStream
ObjectOutputStream
() . .
. , , , . , , .
transferFrom , , , , .
JDK.
Sun JVM GC. GC , ByteBuffers . , .
, , JVM . , ByteBuffer SocketChannel -.
The workaround is to use a small number of direct buffers yourself and save them for reuse.
Source: https://habr.com/ru/post/1696544/More articles:Use table metadata for select statement in SQL Server? - sqlSQL Server Date Conversion Error - datetimeSQL Server 2k5 memory consumption? - performanceOptimization for low bandwidth - optimizationGlobalization Architecture - c #Failure of the .StartTime process - c #Virtual Disk Extension - virtualizationWhich 3D cards support full scene smoothing? - openglStop flashing taskbar - c #GUI tool for quick development? - user-interfaceAll Articles