Frage

Ich glaube, ich meine Heap-Größe in NetBeans auf 1 GB erhöht, da ich nicht die Konfiguration geändert wie folgt aussehen:

netbeans_default_options="-J-Xmx1g ......

Nachdem ich NetBeans neu gestartet wird, kann ich sicher sein, dass mein app 1 GB jetzt gegeben?

Gibt es eine Möglichkeit, dies zu überprüfen?

War es hilfreich?

Lösung

Mit diesem Code:

// Get current size of heap in bytes
long heapSize = Runtime.getRuntime().totalMemory(); 

// Get maximum size of heap in bytes. The heap cannot grow beyond this size.// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();

 // Get amount of free memory within the heap in bytes. This size will increase // after garbage collection and decrease as new objects are created.
long heapFreeSize = Runtime.getRuntime().freeMemory(); 

Es war nützlich für mich, es zu wissen.

Andere Tipps

Sie können jconsole (Standard bei den meisten JDKs) verwenden Speichergrößen von jedem Java-Prozess zu überprüfen.

public class CheckHeapSize {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        long heapSize = Runtime.getRuntime().totalMemory(); 

        // Get maximum size of heap in bytes. The heap cannot grow beyond this size.// Any attempt will result in an OutOfMemoryException.
        long heapMaxSize = Runtime.getRuntime().maxMemory();

         // Get amount of free memory within the heap in bytes. This size will increase // after garbage collection and decrease as new objects are created.
        long heapFreeSize = Runtime.getRuntime().freeMemory(); 

        System.out.println("heapsize"+formatSize(heapSize));
        System.out.println("heapmaxsize"+formatSize(heapMaxSize));
        System.out.println("heapFreesize"+formatSize(heapFreeSize));

    }
    public static String formatSize(long v) {
        if (v < 1024) return v + " B";
        int z = (63 - Long.numberOfLeadingZeros(v)) / 10;
        return String.format("%.1f %sB", (double)v / (1L << (z*10)), " KMGTPE".charAt(z));
    }
}

Anhänge mit jvisualvm von Sun Java 6 JDK. Startup-Flags aufgelistet.

Sie können das Tool verwenden Eclipse Memory Analyzer-Tool http://www.eclipse.org/mat/ .

Es ist sehr nützlich.

Persönlicher Favorit für wenn jvisualvm ist übertrieben oder Sie brauchen cli-only: jvmtop

JvmTop 0.8.0 alpha   amd64  8 cpus, Linux 2.6.32-27, load avg 0.12
https://github.com/patric-r/jvmtop

PID MAIN-CLASS      HPCUR HPMAX NHCUR NHMAX    CPU     GC    VM USERNAME   #T DL
3370 rapperSimpleApp  165m  455m  109m  176m  0.12%  0.00% S6U37 web        21
11272 ver.resin.Resin [ERROR: Could not attach to VM]
27338 WatchdogManager   11m   28m   23m  130m  0.00%  0.00% S6U37 web        31
19187 m.jvmtop.JvmTop   20m 3544m   13m  130m  0.93%  0.47% S6U37 web        20
16733 artup.Bootstrap  159m  455m  166m  304m  0.12%  0.00% S6U37 web        46

Überprüfen Sie Ihre Java-Anwendung Heap-Größe und CPU-Zeit Verwendung JProfiler Tools, die Ihre JVM zugreifen und zeigt alle Heap und CPU-Zeit Zuordnung

Stecker in für Eclipse und intellej Idea IDE

Link zum Download JProfiler

http://www.ej-technologies.com/download/jprofiler/files

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top