Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are custom jvm properties?

Tags:

java

eclipse

jvm

I am new to Java and I have come across the term "custom JVM properties" and how to run configurations with custom JVM properties in eclipse. I want to understand what it really is and how it can help me as a programmer.

like image 492
d1729 Avatar asked Jan 06 '23 11:01

d1729


2 Answers

"jvm properties" concept is a way of making a property (name/value pair) JVM wide. Once you pass a property to the jvm, it becomes accesible in every point of that jvm.

how to pass a property to a jvm:

you can pass properties by command line (-Dproperty_name1=property_value1 -Dproperty_name2=property_value2 ...) at jvm startup,

or

in a running jvm by calling System.getProperties().load(inputStream) from a property file.

or

in a running jvm by calling System.setProperty("property_name1", "property_value1")

how to reach that property:

either way, these properties become JVM wide and you can reach them in every point of your application by calling System.getProperty("property_name1") ...

this docement may help you understanding the properties concept and usage.

example:

package so;
public class SomeClass {
    public void someMethod() {
        System.setProperty("my_pet_name", "boomerang");
    }
}

after calling someMethod() at any point in your application, then you can read it in any other class like this:

package so;
public class SomeOtherClass {
    public void someOtherMethod() {
        String myPetName = System.getProperty("my_pet_name");
        System.out.println(myPetName);
    }
}
like image 152
guleryuz Avatar answered Jan 11 '23 03:01

guleryuz


If you are just starting out, this is not something you need to worry about or something that will affect you at all. JVM parameters are ways that you can tune the JVM for your program. The most common use for these is to adjust the memory used by Java or tune Garbage Collection algorithm.

like image 34
puhlen Avatar answered Jan 11 '23 03:01

puhlen