Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么我会在linux虚拟机上遇到内存不足错误,但在普通Windows 10上却可以正常工作?_Java_Linux - Fatal编程技术网

Java 为什么我会在linux虚拟机上遇到内存不足错误,但在普通Windows 10上却可以正常工作?

Java 为什么我会在linux虚拟机上遇到内存不足错误,但在普通Windows 10上却可以正常工作?,java,linux,Java,Linux,我的命令行java程序在Windows 10工作站上运行时可以工作,该工作站具有分配1GB RAM的双核CPU 然而,当我在一个有四个VCPU和12GB内存的Ubuntu虚拟机上运行它时,它遇到了内存不足的错误 这两种方法都使用-Xms和-Xmx来运行,并相应地设置为相同的值 这是一个奇怪的错误 更新: 1) 我不能分享代码,也不能让人觉得傲慢或其他什么,但我认为代码没有任何问题 2) 错误如下: # # There is insufficient memory for the Java Run

我的命令行java程序在Windows 10工作站上运行时可以工作,该工作站具有分配1GB RAM的双核CPU

然而,当我在一个有四个VCPU和12GB内存的Ubuntu虚拟机上运行它时,它遇到了内存不足的错误

这两种方法都使用-Xms和-Xmx来运行,并相应地设置为相同的值

这是一个奇怪的错误

更新: 1) 我不能分享代码,也不能让人觉得傲慢或其他什么,但我认为代码没有任何问题

2) 错误如下:

#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 12288 bytes for committing reserved memory.
# Possible reasons:
#   The system is out of physical RAM or swap space
#   In 32 bit mode, the process size limit was hit
# Possible solutions:
#   Reduce memory load on the system
#   Increase physical memory or swap space
#   Check if swap backing store is full
#   Use 64 bit Java on a 64 bit OS
#   Decrease Java heap size (-Xmx/-Xms)
#   Decrease number of Java threads
#   Decrease Java thread stack sizes (-Xss)
#   Set larger code cache with -XX:ReservedCodeCacheSize=
# This output file may be truncated or incomplete.
#
#  Out of Memory Error (os_linux.cpp:2627), pid=22403, tid=0x00007f52f9f2c700
#
# JRE version: Java(TM) SE Runtime Environment (8.0_101-b13) (build 1.8.0_101-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.101-b13 mixed mode linux-amd64 compressed oops)
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
顺便说一句,我的虚拟机的最大内存是12GB,我使用了-Xms12160m-Xmx12160m。
至于我的工作站,我的最大内存是2GB,但我使用了-Xms1024m-Xmx1024m

,因此在Linux系统上,您似乎要求它保留完整的12Mbs作为初始堆大小;这并不实际,因为它显然需要内存来存储其他东西(代码、操作系统等)


从其他问题来看,似乎很明显,最小值的默认值是物理RAM的1/64。

如果没有看到一些代码,很难为您提供帮助。您能提供一些其他信息吗?比如你的程序做什么?或者发布错误我知道你有一个很好的答案,但我想我应该指出另一个可能的原因:类似的事情发生在我身上,一个使用了许多文件句柄进行网络I/O的程序。它可能不再是这种方式,但当时Linux(默认情况下)可以处理2000-3000个文件句柄,windows可以处理20000个左右。当Linux的文件句柄用完时,Java中出现了一种非常误导人的“内存不足”情况(当我看到你的问题时,我想到了这一点)。