Issue
guys, this is probably a dumb question, but I can't handle it myself. So, I am trying to apply VM arguments in Netbeans 10 for a class (it is from a tutorial I am reading):
public class GCDemo {
// 8.4MB approx. (2M entries * 4b)
static final int[] iArray = new int[2*1024*1024];
public static void main(String[] a) {
}
}
The VM arguments are shown here:
When I run this class everything works okay. Here is the output:
Heap
def new generation total 4288K, used 632K [0x00000000ff200000,
0x00000000ff6a0000, 0x00000000ff6a0000)
eden space 3840K, 16% used [0x00000000ff200000, 0x00000000ff29e3b0,
0x00000000ff5c0000)
from space 448K, 0% used [0x00000000ff5c0000, 0x00000000ff5c0000,
0x00000000ff630000)
to space 448K, 0% used [0x00000000ff630000, 0x00000000ff630000,
0x00000000ff6a0000)
tenured generation total 9600K, used 8192K [0x00000000ff6a0000,
0x0000000100000000, 0x0000000100000000)
the space 9600K, 85% used [0x00000000ff6a0000, 0x00000000ffea0010,
0x00000000ffea0200, 0x0000000100000000)
Metaspace used 2537K, capacity 4486K, committed 4864K,
reserved 1056768K
class space used 274K, capacity 386K, committed 512K, reserved
1048576K
BUILD SUCCESSFUL (total time: 0 seconds)
However for another class, called Test in the same package:
public class Test {
public static void main(String[] args) {
System.out.println("TEST");
}
}
The output shows TEST in the command-line but also shows the run configuration of the above class GCDemo
Here is the output of the Test class:
TEST
Heap
def new generation total 4288K, used 632K [0x00000000ff200000,
0x00000000ff6a0000, 0x00000000ff6a0000)
eden space 3840K, 16% used [0x00000000ff200000, 0x00000000ff29e3b0,
0x00000000ff5c0000)
from space 448K, 0% used [0x00000000ff5c0000, 0x00000000ff5c0000,
0x00000000ff630000)
to space 448K, 0% used [0x00000000ff630000, 0x00000000ff630000,
0x00000000ff6a0000)
tenured generation total 9600K, used 0K [0x00000000ff6a0000,
0x0000000100000000, 0x0000000100000000)
the space 9600K, 0% used [0x00000000ff6a0000, 0x00000000ff6a0000,
0x00000000ff6a0200, 0x0000000100000000)
Metaspace used 2538K, capacity 4486K, committed 4864K,
reserved 1056768K
class space used 274K, capacity 386K, committed 512K, reserved
1048576K
What am I doing wrong? How to specify the run configuration only for the GCDemo class?
Solution
Assuming you want to change JVM args, for an Ant-based project, for each class that has the main method. You probably can use run configurations with some limitations. But keep in mind:
- You can set the currently active run configuration for the whole
project by
select project in project tree -> rigth-click -> set configuration - chose your configuration
from the menu. - Each Run (F6) of your project will use the JVM args you set on the selected configuration. Also it will use the Main class for running your code you have set in the configuration.
- If you run just a single class with the main method in it (select file then Shift+F6) NetBeans would use the JVM args you set for the currently active configuration but it replaces the running class with selected class.
Create two run configurations GCDemo and TestConfig. For the TestConifg leave VM options empty:
Then you can choose between different run configurations:
Answered By - Dmitry.M