适用于所有 类 的 Netbeans VM 选项

Netbeans VM Options applying for all the classes

伙计们,这可能是个愚蠢的问题,但我自己无法解决。因此,我正在尝试在 Netbeans 10 中应用 VM 参数以获得 class(它来自我正在阅读的教程):

public class GCDemo {
    // 8.4MB approx. (2M entries * 4b)
    static final int[] iArray = new int[2*1024*1024]; 
    public static void main(String[] a) { 
    }
}

此处显示了 VM 参数:

当我 运行 这个 class 一切正常。这是输出:

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)

但是对于另一个 class,在同一个包中调用测试:

public class Test {
    public static void main(String[] args) {
        System.out.println("TEST");
    }
}

输出在命令行中显示 TEST 但也显示上述 class GCDemo[= 的 运行 配置33=]

这是测试的输出 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

我做错了什么?如何只为 GCDemo class?

指定 运行 配置

假设您想要更改 JVM args,对于基于 Ant 的项目,对于每个具有 main 方法的 class。您可能可以使用 运行 配置 但有一些限制。但请记住:

  • 您可以为整个设置当前活动的运行配置 菜单中 select project in project tree -> rigth-click -> set configuration - chose your configuration 的项目。
  • 您项目的每个 运行 (F6) 将使用您在 select编辑配置。它还将使用 Main class 来 运行 配置您在配置中设置的代码。
  • 如果你 运行 只是一个带有 main 方法的 class (select file then Shift+F6) NetBeans 将使用您为 当前活动的配置,但它将 运行ning class 替换为 selected class.

创建两个 运行 配置 GCDemo 和 TestConfig。对于 TestConifg,将 VM 选项留空:

然后您可以选择不同的 运行 配置: