Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Cannot get JAVA_OPTS to work

843829May 19 2010 — edited May 20 2010
Hi,

Have a problem getting the JAVA_OPTS env-parameter to work.

I am on a Windows XP system with JRE 1.6.0_12, and have written a test-class:
package info;

import java.lang.management.ManagementFactory;
import java.lang.management.MemoryUsage;

public class MemInfo {

	public static void main(String[] args) {
		MemoryUsage mu = ManagementFactory.getMemoryMXBean()
				.getHeapMemoryUsage();

		Long mIni = mu.getInit();
		Long mMax = mu.getMax();
		Long mUse = mu.getUsed();

		System.err.println("ini=" + mIni);
		System.err.println("max=" + mMax);
		System.err.println("use=" + mUse);
		System.err.println(mu.toString());
	}
}
When I run it with:
  java -Xms1g -Xmx1g info.MemInfo
I get the expected output (max heap size=1GB):
ini=1073741824
max=1065484288
use=1321224
init = 1073741824(1048576K) used = 1321224(1290K) committed = 1065484288(1040512K) max = 1065484288(1040512K)
But when I try to do the same, using JAVA_OPTS:
set JAVA_OPTS=-Xms1g -Xmx1g
java info.MemInfo
I get the default values output (max heap size=1GB) :
ini=0
max=66650112
use=206032
init = 0(0K) used = 206032(201K) committed = 5177344(5056K) max = 66650112(65088K)
Isnt JAVA_OPTS supposed to work like this?
Or what am I missing?

/rop

Comments

843829
JAVA_OPTS is not an environment variable that the java executable will recognize on it's own. Instead, various scripts which wrap the start up of java will often use an environment variable named JAVA_OPTS to configure the java executable (for example, the tomcat startup script does this).

If you are invoking the java executable directly, via a shell, and you want to use an environment variable named JAVA_OPTS when you start java, the use:

java %JAVA_OPTS% info.MemInfo

or create a script that always does the java %JAVA_OPTS% part for you, and invoke that instead of invoking java directly.
843829
Aha, I see.
Thanks for help!
843829
Or you can use one of
_JAVA_OPTIONS
JAVA_TOOL_OPTIONS
1 - 3
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 17 2010
Added on May 19 2010
3 comments
2,991 views