How to add a JVM option to glassfish 4.0?

Kalle Richter picture Kalle Richter · Jul 11, 2014 · Viewed 11.9k times · Source

The glassfish administation guide states that JVM options ought to be added with asadmin create-jvm-options -Dkey=value:-Dkey=value (https://glassfish.java.net/docs/4.0/administration-guide.pdf, S. 120). Of course the examples don't include the interesting and pedagogical important case of adding options containing : and options starting with -XX instead of -D. It is explained to escape : with \, though. Invoking asadmin create-jvm-options -XX\:MaxPermSize=1024m:-Xmx4096 adds the two options without removing \ which (correctly) prevents the (wrong) option to be recognized. What is the correct way to proceed here?

How to overwrite existing options? If the option name is specified with the same value, asadmin create-jvm-options complains that the option is already present, the another value is specified, the values are both present (-> which one is used?). I don't really have to parse and evaluate the output of asadmin list-jvm-options, do I?

How do I find out whether the options have been added or not, i.e. whether I have to restart the domain? Same question here: I don't really have to parse and evaluate the output of asadmin list-jvm-options before and after adding options, do I?

Answer

unwichtich picture unwichtich · Jul 13, 2014

What is the correct way to proceed here?

You have to delete the JVM option with asadmin delete-jvm-options:

asadmin delete-jvm-options '-XX\:MaxPermSize=192m'

Then add the option again with the new value:

asadmin create-jvm-options '-XX\:MaxPermSize=1024m'

A restart of the server is always required after changing JVM options.

How to overwrite existing options? If the option name is specified with the same value, asadmin create-jvm-options complains that the option is already present, the another value is specified, the values are both present (-> which one is used?). I don't really have to parse and evaluate the output of asadmin list-jvm-options, do I?

I guess this problem is obsolete if you follow the above instructions.

How do I find out whether the options have been added or not, i.e. whether I have to restart the domain? Same question here: I don't really have to parse and evaluate the output of asadmin list-jvm-options before and after adding options, do I?

The asadmin command tells you if it has successfully added or deleted an option. If you try to delete an option which doesn't exist, asadmin will tell you that no option was deleted because it didn't exist.

Update:

In order to delete option I have to know both key and value (what do I do if the option set is -XX:MaxPermSize=193m -> it won't be deleted, but asadmin will produce a second option (the order is unclear), therefore I would have to parse the output of asadmin list-jvm-options).

Why should it have the value 193m if you didn't set that before (and then you probably know it)? And if it has this value, yes you are right, you would have to parse the output of list-jvm-options to find it out. You could also write a script which tries to delete the value by increasing the parameter (192m, 193m, 194m and so on), but that would take a long time to complete.

How does asadmin tell me this (return code, output, ...)?

It outputs human-readable messages like this:

deleted 1 option(s)
Command delete-jvm-options executed successfully.

or

created 1 option(s)
Command create-jvm-options executed successfully.

Try for yourself to see the different messages.

I'm referring to GF 4.0, so links to the 3.0.1 admin guide are obsolete.

They aren't, the GlassFish administration and asadmin are 99,9% equal in GlassFish 3 and 4.

What about the escaping issue?

I can't reproduce that, maybe it helps to set only one value at a time or to wrap param and value in quotation marks.

See also: