I am basically a Weblogic administrator and want to simulate a memoryless situation by deploying very simple Java code (war / ear file) in my Weblogic instance.
I have very little knowledge about Java coding, so can someone provide me with sample code that I can easily pack as a war and deploy?
That should be enough:
long[][] ary = new long[Integer.MAX_VALUE][Integer.MAX_VALUE];
This will try to allocate 2 ^ 31 + 1 memory blocks, each 2 ^ 34 bytes in size.
You can do final long[] l = new long[Integer.MAX_VALUE]; It will allocate 16 GB - 8 bytes.
final long[] l = new long[Integer.MAX_VALUE];
Or you can just throw new OutOfMemoryError();
throw new OutOfMemoryError();
To simulate consumed memory over time, try:
List<long[]> list = new LinkedList<long[]>(); while (true) { list.add(new long[65536]); // an arbitrary number // sleep(1) perhaps? }