标签:启动 runnable proc jvm map homepage 查看 通过 退出
JVM内存不足导致进程死掉. Native memory allocation (mmap) failed to map
# There is insufficient memory for the Java Runtime Environment to continue. # Native memory allocation (mmap) failed to map 1786867712 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:2673), pid=28610, tid=139813184919296 # # JRE version: Java(TM) SE Runtime Environment (8.0_40-b26) (build 1.8.0_40-b26) # Java VM: Java HotSpot(TM) 64-Bit Server VM (25.40-b25 mixed mode linux-amd64 compressed oops) #
很明显是由于服务器的内存不足造成
内存不够用分两种情况
去证实是最重要的, 上面的都是我的推测
一台内存是1G的linux服务器
total used free shared buffers cached Mem: 984 119 864 0 2 20 -/+ buffers/cache: 97 886 Swap: 2044 45 1999
物理内存+swap内存 在 3G左右 (886+1999)
程序如下
package org.hejinbin.memory.test; import java.io.IOException; /** * 用于演示内存不足导致JAVA进程退出, 注意:输入的size勿导致超出int (1024 * 1024 * size) * * @author 何锦彬 QQ 277803242(包子) 2016.12.29 */ public class Test { public static void main(String[] args) throws IOException, InterruptedException { new Thread(new Runnable() { public void run() { try { //接收测试内存的大小,单位m byte[] byteSize = new byte[50]; System.out.print("input want to allocation memory:"); int temp = System.in.read(byteSize); String sizeStr = new String(byteSize, 0, temp); int size = Integer.parseInt(sizeStr.trim()); System.out.println(1024 * 1024 * size); byte[] bt = new byte[1024 * 1024 * size]; System.out.println("succ..allocation: " + size + "m"); //阻30分,防止垃圾回收 Thread.sleep(1000 * 60 * 30); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }).start(); while (true) { //1分钟后报告 Thread.sleep(1000 * 60); System.out.println(Thread.currentThread().getId() + ": i‘m alive"); } } }
证实推测1:
运行程序,输入1000 (这里只要超过了年龄代内存其实就会抛出异常)
输出 alive, 证明了推测1,使用内存超出了并不会导致JAVA进程死掉
证实推测2:
input want to allocation memory:
证实了推测2
结论: 如今微服务流行(趁点热度)。很多进程同时在一台服务器上跑, 必须注意,分配给JAVA的内存只和一定在服务器的可用内存之内。不然很有可能突然被linux干掉一个进程
最后还有个以为,为啥我的进程被killed之后,并没有产生hs_err_pid*.log的日志呢?
标签:启动 runnable proc jvm map homepage 查看 通过 退出
原文地址:http://www.cnblogs.com/springsource/p/6233931.html