【问题标题】:Netbeans VM Options applying for all the classes适用于所有课程的 Netbeans VM 选项
【发布时间】:2020-04-15 09:00:24
【问题描述】:

伙计们,这可能是一个愚蠢的问题,但我自己无法处理。所以,我试图在 Netbeans 10 中为一个类应用 VM 参数(它来自我正在阅读的教程):

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 参数如下所示:

当我运行这个类时,一切正常。这是输出:

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)

但是对于另一个类,在同一个包中称为 Test:

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

输出在命令行中显示TEST,但也显示了上述类GCDemo

的运行配置

这是Test类的输出:

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类指定运行配置?

【问题讨论】:

    标签: java netbeans garbage-collection arguments


    【解决方案1】:

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

    • 您可以为整体设置当前活动的运行配置 select project in project tree -> rigth-click -> set configuration - chose your configuration 从菜单中进行项目。
    • 项目的每次运行 (F6) 都将使用您在 选择的配置。它还将使用 Main 类来运行您在配置中设置的代码。
    • 如果您只运行一个包含 main 方法的类(选择 文件然后 Shift+F6) NetBeans 将使用您为 当前活动的配置,但它将正在运行的类替换为 所选课程。

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

    然后您可以在不同的运行配置之间进行选择:

    【讨论】:

    • 是的,效果很好。但是我发现在 Eclipse IDE 中分离这些运行配置更容易。我不知道为什么 Netbeans 不让每个类都具有“运行方式”功能。感谢您的帮助!
    猜你喜欢
    • 2023-04-11
    • 2021-04-04
    • 2015-02-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多