All links of one day
in a single page.
<Previous day - Next day>

rss_feedDaily RSS Feed
floral_left The Daily Shaarli floral_right
——————————— December 1, 2020 - Tuesday 01, December 2020 ———————————
Java - OutOfMemoryError - HeapDump - Code - JVM - Error -

Pour la troisième solution qui consiste à passer des options à la JVM :

java -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=file_or_dir_path Main.java

Note : Si c'est un répertoire qui est spécifié, alors le fichier sera nommé avec le numéro du pid. Par exemple java_pid22540.hprof .

Et pour tester ces options, cette main simple génère une OutOfMemoryError :

public static void main(String[] args) throws Exception {

        int dummyArraySize = 15;
        System.out.println("Max JVM memory: " + Runtime.getRuntime().maxMemory());
        long memoryConsumed = 0;
        try {
            long[] memoryAllocated = null;  
            for (int loop = 0; loop < Integer.MAX_VALUE; loop++) {
                memoryAllocated = new long[dummyArraySize];
                memoryAllocated[0] = 0;
                memoryConsumed += dummyArraySize * Long.SIZE;
                System.out.println("Memory Consumed till now: " + memoryConsumed);
                dummyArraySize *= dummyArraySize * 2;
                Thread.sleep(500);
            }
        } catch (OutOfMemoryError outofMemory) {
            System.out.println("Catching out of memory error");
            //Log the information,so that we can generate the statistics (latter on).
            throw outofMemory;
        }
    }
-