Skip to content

Instantly share code, notes, and snippets.

@PavlikPolivka
Created June 25, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PavlikPolivka/d2342a4490b05e37f53ef60cc6719225 to your computer and use it in GitHub Desktop.
Save PavlikPolivka/d2342a4490b05e37f53ef60cc6719225 to your computer and use it in GitHub Desktop.
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.stream.Stream;
public class OutOfMemoryExample {
static BlockingQueue<byte[]> blockingQueue = new LinkedBlockingQueue<>();
public static void main(String[] args) {
new Thread(() -> Stream.generate(() -> 1L).forEach(o -> {
blockingQueue.offer(new byte[5 * 1024 * 1024]);
try {
Thread.sleep(100);
} catch (Exception e) {
//noop
}
})).start();
new Thread(() -> Stream.generate(() -> 1L).forEach(o -> {
try {
blockingQueue.take();
Thread.sleep(200);
} catch (Exception e) {
//noop
}
})).start();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment