A Java program that intentionally consumes memory memoryeater

Source: Internet
Author: User

The testing server provided by the company is VMware, claiming to give me 6G,

Physical memory is actually on demand. Until the real 6G physical memory, the lily is cold.

See the following article, think deliberately using Java programs to occupy 6G of memory, and then the invasion to the memory of the release,

It might be a good idea to use a real-world program, such as Oracle Database.

(Does a batch put in the plan task, every morning to work before the execution, will be much better?) )

Import Java.util.Vector;
Import Java.io.BufferedReader;
Import java.io.IOException;
Import Java.io.InputStreamReader;

public class Memoryeater
{
public static void Main (string[] args)
{
Vector v = new vector ();
try {
for (int i = 1; i < 4096; i++)//4K
{
byte b[] = new byte[1048576]; 1M
V.add (b);
Thread.Sleep (1000);
Runtime RT = Runtime.getruntime ();
System.out.println ("Free Memory" + rt.freememory ());
}

Readconsole ();
} catch (Exception e)
{
}


}

public static void Readconsole () throws IOException {
BufferedReader br = new BufferedReader (new InputStreamReader (system.in));
System.out.print ("Enter String");
String s = br.readline ();

}
}

$ java-xmx1024m Memoryeater

Http://alvinalexander.com/blog/post/java/java-program-consume-all-memory-ram-on-computer

A Java program that intentionally consumes memory memoryeater

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.