IBM Support

How RPGLE Starts the JVM When Calling a Java Method

Troubleshooting


Problem

This document provides information about how RPGLE starts the Java Virtual Machine (JVM) when calling a Java method.

Resolving The Problem

Some facts to remember about the Java Virtual Machine (JVM) and RPG are:

o

You are only allowed to create a JVM once per process (per job). That means that once you have started a JVM in that job, you can end Java but you cannot restart it in that same job. You will need a new job.
oWhen using the JAVA (or RUNJVA) CL commands, a new job is started under the covers to run the JVM in so it gives the appearance of being able to run Java over and over in the same job.
oQSH command works the same as JAVA or RUNJVA; the JVM is started in a different job.
oRPG does not create its own JVM, and it does not end the JVM when the program ends. (RPG never ends the JVM.)
When an RPG program calls a Java method using the RPG EXTPROC(*JAVA) support, the RPG runtime determines if there is already a JVM active in the job. If there is, it just attaches to the current JVM to make the method call. If there is no JVM yet, the RPG runtime starts the JVM.

The JVM started by RPG can be used by any other application on the system that wants to use JNI. Normally, after the JVM has been started in the job, any RPG program (or other program) can use Java Native Interface (JNI) to call a Java method, assuming the Java version and CLASSPATH were set up correctly when the JVM was started.

If you call an RPG program that calls a Java method and you receive message RNX0301 and then you correct the CLASSPATH, the RPG program will continue to receive the error until you end the job and call the RPG program again. Also, if you call a Java class from RPG and then modify the class, the RPG program will continue to pick up the old class until the job ends.
----------------------------------------------------------

You can control which version of the JVM is used:
V7R1M0 and beyond:
Set the JAVA_HOME environment variable prior to any Java calls in the job.
https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_72/rzaha/multjdk.htm

V6R1M0 and older:
The version is set by the QIBM_RPG_JAVA_PROPERTIES environment variable before the JVM is started. Type the following command:

ADDENVVAR ENVVAR(QIBM_RPG_JAVA_PROPERTIES) VALUE('-Djava.version=1.5;') REPLACE(*YES)

Notes: Keep the following in mind when using the above environment variable:
1.The properties are case sensitive, so ensure you specify the value in the following way: -Djava.version.
2.The semicolon in -Djava.version=1.5; is necessary for the QIBM_RPG_JAVA_PROPERTIES environment variable.

The RPG runtime uses the last character of the string as the separator between the options. If you do not put in the semicolon, it would use the 5 as the separator character and pass -Djava.version=1. as the first option. If you have ('-Djava.version=1.5;-Dsomething=whatever;') as the value for this environment variable, then the RPG runtime will pass the following properties to Java:

Note: If there is no semicolon after ('-Djava.version=1.5'), you would receive message JVAB53D that states "Java Development Kit could not be found." You must include the semicolon.

 -Djava.version=1.5
   -Dsomething=whatever

[{"Type":"MASTER","Line of Business":{"code":"LOB57","label":"Power"},"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SWG60","label":"IBM i"},"Platform":[{"code":"PF012","label":"IBM i"}],"Version":"7.1.0"}]

Historical Number

403163516

Document Information

Modified date:
18 December 2019

UID

nas8N1015168