增加 Scala 的 JVM 堆大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1441373/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 01:38:56  来源:igfitidea点击:

Increase JVM heap size for Scala?

command-linescalajvmheap

提问by Jay Conrod

I have a Scala data processing tool which is failing with a java.lang.OutOfMemoryErrorexception. The tool needs to make a couple passes over a large data file (the one I'm working on is over 700MB), so it would be convenient if the entire thing could be stored in memory.

我有一个 Scala 数据处理工具,它因java.lang.OutOfMemoryError异常而失败。该工具需要对大型数据文件进行几次传递(我正在处理的文件超过 700MB),因此如果可以将整个文件存储在内存中会很方便。

I run the tool from the command line or from a Bash script using the "scala" runner. How do I increase the JVM heap size for this? I've tried passing -Xmx1024m, but it does not recognize this argument. I'm using a nightly build of Scala 2.8.0 (r18678).

我使用“scala”运行程序从命令行或 Bash 脚本运行该工具。如何为此增加 JVM 堆大小?我试过通过-Xmx1024m,但它不承认这个论点。我正在使用 Scala 2.8.0 (r18678) 的夜间版本。

采纳答案by Synesso

The JAVA_OPTS environment variable is used to specify the options passed to the java command. See the Scala manpagefor details.

JAVA_OPTS 环境变量用于指定传递给 java 命令的选项。有关详细信息,请参阅Scala 联机帮助页

回答by Geoffrey Irving

You can pass options to the JVM via -J. E.g.,

您可以通过 -JEg 将选项传递给 JVM,

scala -J-Xmx2g ...

回答by Jay Conrod

Based on Joe's suggestion, I looked at the scala program, which is a Bash script that calls java with various Scala specific arguments. It allows extra command line arguments to be passed to Java through the JAVA_OPTS environment variable. So you can increase the heap size like this:

根据 Joe 的建议,我查看了 scala 程序,这是一个 Bash 脚本,它使用各种 Scala 特定参数调用 java。它允许通过 JAVA_OPTS 环境变量将额外的命令行参数传递给 Java。所以你可以像这样增加堆大小:

JAVA_OPTS="-Xmx2g" scala classname arguments...

回答by Daniel C. Sobral

Edit JAVA_OPTS.

编辑JAVA_OPTS

回答by Joe

As a hack you can edit the scala/bin/scalafile to edit the parameters for the javacommand. Not pretty.

作为黑客,您可以编辑scala/bin/scala文件以编辑java命令的参数。不漂亮。