Javac -Xmx 限制虚拟机使用
有没有办法限制javac的最大虚拟内存使用量?
运行java时,我可以使用“-XmxAm”(其中A是可用兆字节数)来运行它来限制它。
有没有类似javac的东西?
Is there any way to limit maximum virtual memory usage of javac?
When running java, I can run it with "-XmxAm" (where A is number of free megabytes) to limit it.
Is there anything for javac like that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用
-J
选项为javac(以及大多数具有自己的本机启动器的java程序)提供相同的运行时选项。按照惯例,所有此类选项都直接传递到运行时系统。因此,在您的情况下,您可以调用以很少的内存运行 javac。当然,正如reseter所说,这种方式的用途有限,因为javac可能确实需要一些内存来编译。不过,在真正的大型项目中,您可能希望通过这种方式增加内存。
You can give the same runtime options to javac (and most java programs with an own native starter) by using
-J
options. By convention, all such options are passed directly to the runtime system. So, in your case, you can invoketo run javac with very little memory. Of course, as reseter said, it is of limited use this way, since javac may really need some amount of memory to compile. On really big projects, you may want to increase the memory this way, though.
我不这么认为。编译器需要构建完整的语法树等才能工作,因此限制其内存使用并不是最好的主意。
I don't think so. The compiler will need to build a full syntax tree, etc, in order to work, so limiting its memory usage wouldn't be the best of ideas.
对于 unix shell,您可以使用 ulimit 命令 (http://ss64.com/bash/ulimit.html )。
-v 选项
是 javac 进程的虚拟内存限制。不过,它需要大量的虚拟内存,否则会出现以下错误,
注意:java 方法 - thread.sleep 不会计入 ulimit 时间限制(实时与 CPU 时间),因此,如果您将 ulimit 与 java 文件一起使用,则 java 文件可以继续随心所欲地睡觉。
For a unix shell, you can use the ulimit command (http://ss64.com/bash/ulimit.html).
The
-v option
is the virtual memory limit to the javac process.However, it requires a lot of virtual memory, otherwise the following error occurs,
Note: java method - thread.sleep will not be counted in ulimit time limit (real time vs CPU time), so if you are using ulimit along with a java file, the java file can just keep sleeping as it likes.