0

I am developing a Application using JavaFx 2.2.3 and jdk 1.7.0_09.This application will run on Windows, and Mac Osx. The problem is I am getting Out-Of-Memory. I know -Xms and -Xmx are used to tweak JVM memory. But requirement is we have to set JVM memory using java code as This is a desktop application so we can't tweak JVM on every system.

Now I find a solution for windows

proc = Runtime.getRuntime().exec("cmd.exe /c java -Xms250m -Xmx1024m -jar \"application.jar\" /n");

By using this code i can increase JVM memory before starting my Application jar. But this is a solution for Windows only.

Can any one tell similar kind of code For Mac.

4

2 回答 2

1

首先,您需要找到安装 java 的位置。Apple 的这份文档解释了如何做到这一点 - http://developer.apple.com/library/mac/qa/qa1170/_index.html

字符串 JAVA=...

proc = Runtime.getRuntime().exec(JAVA+ " -Xms250m -Xmx1024m -jar "application.jar");

所以让我们假设Java在'/usr/bin/java',那么:

proc = Runtime.getRuntime().exec("/usr/bin/java -Xms250m -Xmx1024m -jar application.jar");

请注意,如果您需要从 'proc' 捕获输出,则可以执行以下操作:

DataInputStream in = new DataInputStream(proc.getInputStream());
while ((ls_str = ls_in.readLine()) != null) {
  // Do something with the output from proc
  System.out.println(ls_str);
}
于 2012-11-03T08:00:17.223 回答
0

您不能为已经运行的 JVM 增加内存。标准方法是提供添加 JVM 参数的启动脚本。或者如果你使用webstart,我认为堆大小可以在jnlp文件中配置。

于 2012-11-03T08:23:55.690 回答