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
You can configure custom JVM properties to run your application by specifying them in Run Configurations
.
Follow the below steps to configure:
Run as
then Run Configurations
Arguments
tab and give your custom parameters in the VM Arguments
box 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.
"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);
}
}