简体   繁体   English

限制Java RAM使用率?

[英]Limit Java RAM usage?

we use Java for our project www.aerospaceresearch.net/constellation and use Java diretcly out of an uninstalled java bin-folder. 我们将Java用于我们的项目www.aerospaceresearch.net/constellation,并直接从已卸载的Java bin文件夹中使用Java。

We have some troubles with ram usage of this java differing between OS and even 32 and 64bit versions. 我们在操作系统甚至32位和64位版本之间使用该java的ram用法存在一些麻烦。 Is it possible to set an upper limit for ram usage, so that Java does a dynamic rearranging of ram, that it is allways below 150mb for example? 是否可以设置ram使用的上限,以便Java对ram进行动态重新排列,例如始终低于150mb?

That would really help us to solve some minor issues and to bring our app to systems with limited ram capabilities. 这确实可以帮助我们解决一些小问题,并将我们的应用程序带入具有有限内存功能的系统。

Thanks in advance, Andreas 在此先感谢,Andreas

It's difficult to tell from your question, but you may be looking for the -Xmx option in Sun's Oracle's java tool, which sets a maximum size for the Java memory heap. 从您的问题很难看出来,但是您可能正在Sun的 Oracle java工具中寻找-Xmx选项,该选项为Java内存堆设置了最大大小。

For details on the various non-standard features offered by that version of the java tool (including several related to the heap), type java -X at a command prompt. 有关该版本的java工具提供的各种非标准功能(包括与堆相关的一些功能)的详细信息,请在命令提示符下键入java -X For my installed version, that gives me: 对于我安装的版本,这给了我:

java -X
    -Xmixed           mixed mode execution (default)
    -Xint             interpreted mode execution only
    -Xbootclasspath:<directories and zip/jar files separated by :>
                      set search path for bootstrap classes and resources
    -Xbootclasspath/a:<directories and zip/jar files separated by :>
                      append to end of bootstrap class path
    -Xbootclasspath/p:<directories and zip/jar files separated by :>
                      prepend in front of bootstrap class path
    -Xnoclassgc       disable class garbage collection
    -Xincgc           enable incremental garbage collection
    -Xloggc:<file>    log GC status to a file with time stamps
    -Xbatch           disable background compilation
    -Xms<size>        set initial Java heap size
    -Xmx<size>        set maximum Java heap size
    -Xss<size>        set java thread stack size
    -Xprof            output cpu profiling data
    -Xfuture          enable strictest checks, anticipating future default
    -Xrs              reduce use of OS signals by Java/VM (see documentation)
    -Xcheck:jni       perform additional checks for JNI functions
    -Xshare:off       do not attempt to use shared class data
    -Xshare:auto      use shared class data if possible (default)
    -Xshare:on        require using shared class data, otherwise fail.

The -X options are non-standard and subject to change without notice.

If you're using a different implementation of Java, those options may vary; 如果您使用的是Java的其他实现,则这些选项可能会有所不同。 and note the warning at the end of the above. 并注意上述末尾的警告。

You could try using something like... 您可以尝试使用类似...

java -Xmx128m BigApp

But you may get out-of-memory errors if your app actually goes over the 128 MB heap limit. 但是,如果您的应用程序实际超过了128 MB的堆限制,则可能会出现内存不足的错误。

[update] On the 64 bit side of things, there is a special parameter that makes 64 bit references take up less space but I can't find it right now. [更新]在64位方面,有一个特殊的参数使64位引用占用更少的空间,但我现在找不到它。 It is standard on one of the new JREs (1.6?). 这是新JRE(1.6?)之一的标准配置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM