User Guide - Using JRE from the Command Line (setting Heap)


Applicable Plans: Standard Plus VPS, Standard Max VPS, all Advanced VPS plans, all Premier VPS plans

Using the Java Runtime Environment (JRE) from the command line.

This document explains how to run Java from the command line and how to set the Heap size.

The default heap size for the JRE is set to a percentage of the memory installed in the physical server.  The default is usually 256 MB, which may be too large for some of the VPS plans.  The heap size needs to be set to a percentage of the memory available to your VPS.  The heap size can be set through a .hotspotrc file in your home directory, a java.sh file in /etc/profile.d or by passing the initial and max heap size parameters in your command. The syntax for that varies depending on the command, so you may want to refer to the official documentation at java.sun.com for the appropriate syntax.

JDK 1.5

To use the JRE version 1.5 provided by eApps, you must also install the JDK version 1.5. The installation of the JDK will create a file in each user's home directory called “.hotspotrc”. This file is used by the JRE to set the heap size for your commands. By editing this file, you will be able to set the heap size for each application's home directory.

To use this file to set the heap size, simply run your command from your home directory. For the 'root' user, this would be /root. For other users, it would be /home/username. If you attempt to run a command outside of your home directory, you will probably get an 'out of memory' error. Copy the .hotspotrc file from /root to your current working directory. For editing the file you may login to your SSH as “root”. Please read the SSH user guide for more details.

Once you login through SSH you will be taken to your home directory. If you are not simply type cd command which will take you to your home directory.

To list all the files in there use the “ls –al” command. You will see the .hotspotrc file listed.

Use any editor to open the file and adjust your Heap Setting. In this example we will use vi editor.

vi .hotspotrc

Press “i” to change to edit mode. Make necessary changes to the value and press “Esc”. To save and exit file type “:wq”(Yes there is a :)

If you do not want to use the .hotspotrc file, there is another way to configure your heap size. Create a file called java.sh and put it in the /etc/profile.d/ directory. Follow the below steps to create the file.

 

vi /etc/profile.d/java.sh

 

Press “i” to enter edit mode and then enter the below line.


export _JAVA_OPTIONS='-Xms64m -Xmx64m'

 

Press “Esc” and then “:wq” to save and exit the file.


You can adjust the max and min amounts. For example:

export _JAVA_OPTIONS='-Xms64m -Xmx256m'

Once you have created this file, you will need to restart your system.

JAVA 6

Java 6 provided by eApps uses the /etc/profile.d/java.sh file to set the heap size. If you have "Java 6 Update 2" installed, this file was created for you during installation with the default heap size of 64m. If you are currently using a older version of Java 6 you can upgrade ( if possible) or create the java.sh file in /etc/profile.d and set your desired heap size with the parameters used below.

vi /etc/profile.d/java.sh

 

Press “i” to enter edit mode and then enter the below line.


export _JAVA_OPTIONS='-Xms64m -Xmx64m'

 

Press “Esc” and then “:wq” to save and exit the file.


You can adjust the max and min amounts. For example:

export _JAVA_OPTIONS='-Xms64m -Xmx256m'

Once you have created this file, you will need to restart your system for the new values to take effect.

 

Setting Java Heap size for specific user

If you need to set heap size for specific user login you may add the below to /home/username/.bash_profile (or /Path_to_users_home_directory/.bash_profile)

export _JAVA_OPTIONS='-Xms64m -Xmx256m'

This values will be set automatically every time the user logs in to SSH.

If you still need assistance contact support@eApps.com with all the details you can include.


Comments

Please login to comment