OutOfMemory error while trying to retrieve a large jar using ZipFileSet

With jdk1.5, I get an OutofMemoryError when trying to retrieve a sufficiently large jar. However, this does not happen on jdk6. Is this due to different default heap / renumber settings for jdk1.5 and jdk6 or is it a bug in jdk1.5 that was fixed in jdk6?

import java.io.*;
import java.util.zip.*;

public class UnZip {
   final int BUFFER = 2048;
   public static void main (String argv[]) {
      try {
         BufferedOutputStream dest = null;
         FileInputStream fis = new FileInputStream(argv[0]);
         ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
         ZipEntry entry;
         while((entry = zis.getNextEntry()) != null) {
            System.out.println("Extracting: " +entry);
            int count;
            byte data[] = new byte[BUFFER];
            // write the files to the disk
            FileOutputStream fos = new FileOutputStream(entry.getName());
            dest = new BufferedOutputStream(fos, BUFFER);
            while ((count = zis.read(data, 0, BUFFER)) != -1) {
               dest.write(data, 0, count);
            }
            dest.flush();
            dest.close();
         }
         zis.close();
      } catch(Exception e) {
         e.printStackTrace();
      }
   }
}
+3
source share
1 answer

Quoting The total heap size in the Configuring Garbage Collection section with the 5.0 Java [tm] virtual machine :

Total pile

(...)

. -XX:MinHeapFreeRatio=<minimum> -XX:MaxHeapFreeRatio=<maximum>, -Xms -Xmx. 32- Solaris ( SPARC Edition) :

-XX:MinHeapFreeRatio= 40
-XX:MaxHeapFreeRatio= 70
-Xms          3670k
-Xmx          64m

64- 30%. 64- .

Java SE 6 HotSpot Virtual Garbage Collection Tuning, :

, . , , DefaultInitialRAMFraction DefaultMaxRAMFraction, . ( .)

                                             Formula  Default
initial heap size     memory / DefaultInitialRAMFraction          memory / 64
maximum heap size     MIN(memory / DefaultMaxRAMFraction, 1GB)    MIN(memory / 4, 1GB)

, 1 , , .

, , Java 6 , 1/4 ( 1 , 4 ), , , , 64 .

+3

Source: https://habr.com/ru/post/1732659/


All Articles