Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I run Minecraft server, over time (a few hours to a few days) the memory usage by Java balloons to take up all available computer memory and the server performance then degrades: lags, players lose their connection, and minecraft shows messages like "[Server thread/WARN]: Can't keep up! Did the system time change, or is the server overloaded? Running 3126ms behind, skipping 62 tick(s)"

Short of stopping and restarting the Minecraft server every time it degrades like this, is there a way to prevent this from happening in the first place?

Thank you for your help.


Operating System: Ubuntu 12.04.3 LTS Server

Server: HP ProLiant DL360 G5, 2 Xeon E5420 @ 2.50 GHz, 16 GB RAM

java version "1.6.0_27"

OpenJDK Runtime Environment (IcedTea6 1.12.6) (6b27-1.12.6-1ubuntu0.12.04.4)

OpenJDK 64-Bit Server VM (build 20.0-b12, mixed mode)

To run Minecraft I use the following, but I have tried different -Xmx -Xms limits with the same problem developing

java -Xmx2048M -Xms2048M -jar minecraft_server.jar nogui

Monitoring memory usage with top, it starts out low and everything works fine for a while:

Tasks: 139 total,   1 running, 138 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.5%us,  0.0%sy,  0.0%ni, 97.4%id,  0.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  16433112k total,  1420264k used, 15012848k free,    10220k buffers
Swap: 16773116k total,    51980k used, 16721136k free,   107432k cached

 5025 tom       20   0 5095m 1.0g  11m S   20  6.5   5:57.76 java
 5437 tom       20   0 17344 1300  952 R    0  0.0   0:00.03 top
    1 root      20   0 24332  660  112 S    0  0.0   0:01.21 init
    2 root      20   0     0    0    0 S    0  0.0   0:00.05 kthreadd

Eventually though, it balloons to using up almost all the memory (97% of the 16GB), RES goes to 15g, VIRT to ~19g:

Tasks: 139 total,   1 running, 138 sleeping,   0 stopped,   0 zombie
Cpu(s):  2.5%us,  0.2%sy,  0.0%ni, 97.6%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:  16433112k total,  16284172k used, 148940k free,    1104k buffers
Swap: 16773116k total,    952160k used, 15820956k free,   33824k cached

 5025 tom       20   0 19.5g  15g 4292 S   20 97.1  27:20.76 java
    1 root      20   0 24332    0    0 S    0  0.0   0:01.21 init
    2 root      20   0     0    0    0 S    0  0.0   0:00.05 kthreadd
share|improve this question
Either, java has a bug (try openjdk if you are using oracle's) or minecraft has a serious memory leak or you just are using your sever too intensively. – Braiam Dec 7 '13 at 21:47
Thanks @Braiam. I just tried setting the default java to "java-7-openjdk-amd64" with "sudo update-alternatives --config java" and restarted Minecraft. I'll see what happens. Now "$ Java -version" gives "1.7.0_25" where before it was "1.6.0_27". Hopefully this makes a difference. The server is only running Minecraft, and only with 4-5 users so it should not be working too hard I think. – Tom Dec 8 '13 at 4:38

Changing the default version of Java to version 7 appears to have corrected the problem; Minecraft server has been running ~ a day without the Java memory leak issue now. It seems that Minecraft 1.7.2 does not work well with the Java version 6. I had previously installed Java 7 as suggested by another post on this forum using:

sudo apt-get install openjdk-7-jre-headless

However I did not realize that this did not automatically become the default version when java was run. To change the default version of java:

sudo update-alternatives --config java


There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
  0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
* 2            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1051      manual mode

Press enter to keep the current choice[*], or type selection number:

I selected '2', the /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java to be the default. After restarting the Minecraft server, the Java memory usage has remained stable at about 1.1g for about a day now with a number of players using the game (no lag, or other error messages in Minecraft). Previously it would have degraded within a few hours under this scenario.

share|improve this answer
Did this solve your issue in the end? – James Heald Apr 7 '14 at 22:59
This won't help as you are simply choosing JRE7 instead of JRE6. – Bhargav Nanekalva Mar 25 '15 at 7:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.