Skip to main content

Fix Tomcat PermGen Space (Out of Memory)

Tomcat production server sometime will hit the following java.lang.OutOfMemoryException: PermGen space error.

java.lang.OutOfMemoryException: PermGen space
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124) 

It’s usually happened when the Tomcat start and stop few times. It’s just funny, however you can fine tune it with some minor changes in the Tomcat configuration setting. By default, Tomcat assigned very little memory for the running process, the solution is actually quite simple.
All you need todo are

1) create setenv.sh or setenv.bat (windows)

2) add this line if not already exist (depend on what os you are using)
   Linux:
    export set JAVA_OPTS="-Xms512m -Xmx2g"

   Windows 
    set JAVA_OPTS="-Xms512m -Xmx2g"

3) Done. Restart Tomcat.

Explanation:
This error are occurs when JVM cannot create new object on memory heap because it pass the heap size. that is why it says out of memory. when your program start it create a heap in memory stated in -Xms parameter. the amount reserved are the number after the parameter. an the suffix after the number are unit size of the heap. k for kilobit; m for megabit; g for gigabit. And also please adjust the amount of memory allocation based on you machine.

-Xmx are the maximum size of the heap in memory. as long as the the object in your memory don't pass this limit you are good. but when you pass this limit then the java.lang.OutOfMemoryException are raised.

Memory Leak:
Normally your program wont pass maximum heap size. But through time your application create more object in the memory and some time collected by java Garbage Collector when the created object not being used anymore by the program. For some reason these object sometimes still have some reference in your program that can cause Memory Leak. If the problem not fixed then Garbage Collector cannot collect this object then eventually the heap became full and you program cannot create more object. 

Comments

Popular posts from this blog

XML Parsing Dengan Java Bag. I (Menggunakan DOM Parser)

Dulu sewaktu kuliah saya pernah pernah berpikir untuk membuat suatu applikasi yang dapat membaca dan menulis file configurasinya sendiri. lalu saya menggunakan text file sebagai media penyimpan konfigurasi.... seiring perkembangan dan jam terbang bertambah sayapun sempat terpikir untuk mengganti text file yang digunakan menjadi XML (Extensible Markup Language) dimana dokumen ini memiliki keunggulan yang sangat banyak. tidak hanya sebagai media penyimpanan konfigurasi, ternyata XML juga banyak digunakan sebagai media penyimpanan data. seperti contoh berikut ini. <?xml version="1.0" encoding="UTF-8"?> <personnel> <employee type="permanent"> <name>Seagull</name> <id>3674</id> <age>34</age> </employee> <employee type="contract"> <name>Robin</name> <id>3675</id> <age>25</age> </employee...

Ubuntu 9.04 x86_64 Run well in Acer Aspire 4530

Hey guys, after a while I didn't update this blog, right now I'm just feeling like to share my happiness. Just want to inform you all that ubuntu 9.04 64bit run well in my laptop... i'm just happy to say to my self welcome back to ubuntu after a while back to windows because ubuntu version lesser than 9.04 doesn't support my laptop. the installation process is simple, much more simple than before. to install ubuntu 9.04 please follow this steps: insert ubutu 9.04 live CD or the alternate version of it set your optical drive as your first boot device at BIOS or press F12 at boot sequence to select which device you want to boot from. select install ubuntu to harddrive wait until boot process done and setup your storage partition (at least 1 ext3/ext4 partition and 1 swap partition fill your name, user name and password. wait until installation progress finished. reboot you laptop now. VIOLA! your ubuntu now ready to use okay let's check so...

Mengapa Karyawan Meninggalkan Perusahaan!

Mengapa karyawan meningggalkan perusahaan (atau paling tidak sering ngedumel)? Berikut ini petikan dari bukunya Haris Priyatna yang berjudul Azim Premji, "Bill Gates" dari India (terbitan Mizania 2007). Azim Premji adalah milyuner dari India yang telah menyulap Wipro, dari sebuah perusahaan minyak goreng menjadi konglomerasi perusahaan dengan salah satunya adalah Wipro Technologies yang merupakan ikon kebangkitan industri teknologi informasi di India. Dia urutan ke-21 orang terkaya di dunia versi Forbes 2007. Azim dikenal sebagai milyuner yang bergaya hidup sederhana. Berikut ini pandangan Premji tentang mengapa karyawan betah dan tidak betah dengan perusahaan. Wipro sendiri memiliki tinkat turn-over (kepindahan) karyawan yang sangat rendah, padahal gajinya tidak lebih tinggi dibandingkan perusahaan sejenis seperti Infosys dan TCS. Mengapa KARYAWAN meninggalkan perusahaan? Banyak perusahaan yang mengalami persoalan tingginya tingkat pergantian karyawan. Betapa or...