Yesterday I encountered a problem with the minecraft server version 1.7.2 and 1.7.4. When a specific user was logging in, the memory use of the minecraft service raised to 100% of the available memory and the server started swapping. This causes a very slow responding server and all the players where disconnected because of a timeout. Every time this users logs in this problem occurs. After some searching I found out it has something to do with the installed java version.
Which java version is installed?
To find out which java version is installed, open a terminal and type:
What should you check/should it be?
There are a few thing to watch for. First there are two creators of usable java packages, a closed source and open source one.
The closed source version is called
sun-java, is currently maintained and developed by Oracle and might not be available in the repositories of your distribution (ate least not in Debian). The open source version is called
openjdk and is most likely available in the repositories of your distribution.
To people who have doubts which one to use, use the
openjdk one, unless you encounter any errors with it. They are for 90% the same, so it is most likely your java application will work the same on both packages. So the fact that the
openjdk one is in the repositories and therefor it is easier to install and maintain makes it the preferable one.
The next thing to check is the version itself. It can be found in the first line of the result of the command above. Currently there are two version which are widely used. The new version number 7 and the older version 6, they might be stated as 1.7 or 1.6. Version 1.7 enables some new features in java, see jdk7 features. I would suggest using version 7 unless you encounter some problems with it.
How to install and choose the java version
- Update the packages list:
sudo apt-get update
- Install the java package:
If you use java on a server without graphical interface:
sudo apt-get install openjdk-7-jre-headless
Else use the following:
sudo apt-get install openjdk-7-jre
The package description of the “headless” package tells you the difference: “This package does not provide dependencies used for the graphical components.”
Choosing the java version
- To choose the java version we should user the
sudo update-alternatives --config java
This will list the available packages like:
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
The one with the star in front of it, is the one which is currently used.
- To change the java version/package, you are able to type the number of the wanted package as stated in the previous command:
Press enter to keep the current choice[*], or type selection number:
Type the number and press enter, or just hit enter to keep the current one selected
- Check the java version:
Which java packages leads to the memory leakage?
openjdk version 6 is installed. This one was causing me the problems.
Which one solved the problem?
openjdk version 7 on the server, the memory leak was gone.