From 6f1e14b649b821cb1ab38c9ae3a3b3e24eb8d05d Mon Sep 17 00:00:00 2001 From: Andrey Shcherbakov Date: Sun, 6 Jan 2019 21:31:51 +0100 Subject: [PATCH] Code for article BAEL-2386 (#5958) * Add code for the article 'Java Primitives versus Objects' * Use JMH for benchmarking the primitive and wrapper classes * Uncomment the benchmarks and remove unused class * Add a binary search tree implementation * Add an example of how to use the binary tree class * Adjust the print statements * Add a code for article #BAEL-2386 --- .../flightrecorder/FlightRecorder.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 core-java/src/main/java/com/baeldung/flightrecorder/FlightRecorder.java diff --git a/core-java/src/main/java/com/baeldung/flightrecorder/FlightRecorder.java b/core-java/src/main/java/com/baeldung/flightrecorder/FlightRecorder.java new file mode 100644 index 0000000000..02c3e96124 --- /dev/null +++ b/core-java/src/main/java/com/baeldung/flightrecorder/FlightRecorder.java @@ -0,0 +1,32 @@ +package com.baeldung.flightrecorder; + +import java.util.ArrayList; +import java.util.List; + +/** + * Simple program that illustrates how to use Java Flight Recorder. + * + * This programs creates a list, inserts objects in it until + * an OutOfMemoryError is thrown. + * + */ +public class FlightRecorder { + + public static void main(String[] args) { + List items = new ArrayList<>(1); + try { + while (true) { + items.add(new Object()); + } + } catch (OutOfMemoryError e) { + System.out.println(e.getMessage()); + } + assert items.size() > 0; + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + System.out.println(e.getMessage()); + } + } + +}