有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java使用集合对10亿个整数进行排序。sort()给出内存不足错误

我试图用集合对10亿个整数的列表进行排序。排序(List)并引发以下异常 线程“main”java.lang.OutOfMemoryError:java堆空间中出现异常 -xms设置为512m,xmx设置为1536m。我该怎么分类呢?我的系统中有8GB内存,所以分配更多物理内存不是问题。我试图给出-xmx 2048m,但vm无法使用该设置进行初始化


共 (2) 个答案

  1. # 1 楼答案

    I tried giving -xmx 2048m but vm could not initialize with that setting.

    您可能正在使用32位JVM,which have a practical max heap size below 2GB。你应该试试64位JVM

    还要注意的是,您应该为程序设置VM参数,而不是为Eclipse设置VM参数(就像您在每个注释中所做的那样)。您可以通过选择Run Run中的下拉菜单,然后运行配置来实现这一点。然后选择你的程序并打开参数面板

  2. # 2 楼答案

    它可能区分大小写,并且应该没有空格,请尝试使用-Xmx2048m

    Nonstandard Options

    -Xmxn

    Specifies the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2 MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is chosen at runtime based on system configuration.

    For server deployments, -Xms and -Xmx are often set to the same value. See Garbage Collector Ergonomics at http://docs.oracle.com/javase/7/docs/technotes/guides/vm/gc-ergonomics.html

    Examples:

    -Xmx83886080

    -Xmx81920k

    -Xmx80m

    docs