我正在实验JVM,并且正在从用户VMOptions.addFieldOption("-XX:", "FlareAllocationThreshold", AllocationProfiler.class, "The number of the Flare objects to be allocated before the Allocation Profiler starts recording. (default: 100)");
获取阈值作为-XX命令行选项。
现在,我正在尝试对其进行一些改进,并为用户提供设置多个阈值的功能。
我尝试做的第一件事就是将FlareAllocationThreshold
从int更改为String,例如"100, 200, 300"
,然后使用以下方法将其转换为整数
public static int[] stringToInts(String line) {
//String line = "100, 200, 300";
String[] parts = line.split(",");
int[] ints = new int[parts.length];
for (int i = 0; i < parts.length; i++) {
ints[i] = Integer.parseInt(parts[i]);
}
return ints;
}
不幸的是,我对JVM有一些限制,例如在该过程中禁止创建新对象,因此禁止使用stringToInts()
。
所以我的问题如下:我可以以某种方式使用-XX命令行选项,该选项使用户有机会选择他/她要使用多少个阈值,例如:-XX:FlareAllocationThreshold_1=100 -XX:FlareAllocationThreshold_2=200 -XX:FlareAllocationThreshold_3=300
(用于3个阈值等) ?