'UNSW - Science

UNSW - Science - HPC

Java

Java is a powerful programing language which allows software to be easily ported between different systems. A large number of tools have been written in Java to avoid the difficulty of having to compile software to make it work on a particular system.

The default version of Java installed on the systems is something that may be upgraded with no warming due to a security issue. As this may cause differences in results the clusters have at least 1 version of Java installed and available via the module command which should be used instead of the system Java.

By default when you use Java on one of the clusters it does not allocate a large enough heap size. For the versions of Java available via the module command the default heap size has been set via the flag -Xmx1g. If you wish to use the system version of Java or change the default heap size then you change it using a similar flag to the one above. For example to set the minimum heap size to 2g use the flag -Xmx1g or set the environment variable _JAVA_OPTIONS=-Xmx2g.

Examples

Here are some examples of how Java may be used on a cluster. You should also look at the FAQ to for additional information.

Java Versions

Running the default Java version from the command line gives the following error.

[z2222222@katana ~]$ java -version
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

By setting the default heap size in the command we get the following result which tells us that the default version of Java on Katana is currently version 7 update 3. (We can achieve the same result by setting _JAVA_OPTIONS as mentioned above).

[z2222222@katana ~]$ java -Xmx1g -version
java version "1.7.0_03"
Java(TM) SE Runtime Environment (build 1.7.0_03-b04)
Java HotSpot(TM) 64-Bit Server VM (build 22.1-b02, mixed mode)

Next we start by running module avail and see what versions of Java are available. For example Katana has (at least) version 6 update 45 and version 7 update 51 installed as modules.

We can now specify a particular version of Java using the module add command and then display the version number which is version 6 update 45. Note that the heap size is automatically set to 1g when we load Java using a module.

[z2222222@katana ~]$ module add java/6u45 
[z2222222@katana ~]$ java -version
Picked up _JAVA_OPTIONS: -Xmx1g
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)

If you have one version of Java loaded via the module command and witch to switch to another version then we can use module swap and then the version available becomes version 7 update 51.

[z2222222@katana ~]$ module swap java/6u45 java/7u51 
[z2222222@katana ~]$ java -version
Picked up _JAVA_OPTIONS: -Xmx1g
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)

A Java Application

One example of software that relies on Java is Picard. Before you run software such as Picard for the first time you should use the command

module help picard/1.109

which will tell you that Picard uses Java and other important information. So we then add the module by typing

module add picard/1.109

and we can now use the software. As above if we just try to call the Jar file in the standard way (i.e. java -jar /share/apps/picard/1.109/ValidateSamFile.jar) then the result will be the following error.

[z2222222@katana ~]$ java -jar /share/apps/picard/1.109/ValidateSamFile.jar
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

If we instead specify the heap size as part of the command as shown below

[z2222222@katana ~]$ java -jar -Xmx1g /share/apps/picard/1.109/ValidateSamFile.jar

then the command will work.

We can also (and this is best practice) load a particular version of Java and then run the command without specifying the maximum heap size as per the following examples.

[z2222222@katana ~]$ module add java/6u45
[z2222222@katana ~]$ java -jar /share/apps/picard/1.109/ValidateSamFile.jar

or

[z2222222@katana ~]$ module add java/7u51
[z2222222@katana ~]$ java -jar /share/apps/picard/1.109/ValidateSamFile.jar

Java Versions Available via Module

Software Name Version
Java 6u45 Java 6u45
Java 7u51 Java 7u51
Java 8u45 Java 8u45
Java 8u91 Java 8u91