I am basically a Weblogic admin and want to simulate out of memory situation through deploying a very simple Java code(war/ear file) in my Weblogic instance.
I have a very little knowledge about Java coding so can someone please provide me a sample code which I can easily pack as war and deploy?
You can do final long[] l = new long[Integer.MAX_VALUE];
It will allocate 16Gb - 8 bytes.
Or you can just throw new OutOfMemoryError();
To simulate the memory being consumed over time try:
List<long[]> list = new LinkedList<long[]>();
while (true) {
list.add(new long[65536]); // an arbitrary number
// sleep(1) perhaps?
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With