Re: How to specify -Xms -Xmx from within the program?
From: Oscar kind (oscar_at_danwa.net)
Date: Sun, 13 Jun 2004 00:22:16 +0200
Princess Morgiah <email@example.com> wrote:
> I was wondering if it were possible to specify the -Xms and -Xmx from
> within a program.
No. These settings determine what the JVM does, and programs only
determine what they do themselves.
> Allthough it is possible to specify these parameters from the commandline,
> it's not a handy way of doing things for users. I don't know whether or not
> these parameters can be set from within a manifest file in a jar, but that
> would also mean starting the program as a jar, which is not very handy while
> developing the software.
These parameters cannot be set in a jar file, but they can be specified in
a Java Web Start description file. Otherwise, use a scripts to start the
JVM and the program (you'll need one script for each platform the program
will run on).
Also note that if you use ANT to compile your program, you can also
automatically build a jar file to execute. This is actually an advantage:
- Your program is exactly as it will be delivered, making testing easier
and more reliable; you don't have to separately test a development and a
- You can include version information in the jar manifest and read it in
your program (note that ANT can automatically increase version numbers
and also creates the manifest for the jar file). I like this option.
> Therefor I would like to know if it were possible to specify these, and
> other settings from withing the code itself.
Not the memory settings of the JVM. Other (system) settings, if they can
be changed, can only be changed through java.lang.System. That is, unless
you're willing to use JNI. In that case you can do anything you have an
os-dependant library for.
> After a quick look at the System class, I found a setProperty method but I
> don't think that's the way to go.
Personally, I don't think that either. But that's more because I believe
that system settings should only be set by a sysadmin. It's unlikely (but
possible) that a Java program is a sysadmin's tool for setting system
-- Oscar Kind http://home.hccnet.nl/okind/ Software Developer for contact information, see website PGP Key fingerprint: 91F3 6C72 F465 5E98 C246 61D9 2C32 8E24 097B B4E2