Exploring further

Let's profile another application that creates a lot of (500) threads; each thread creates ArrayList of 1,000,000 Double values, populating it with random numbers:

class AThread implements Runnable { 
    String name = "default"; 
    private Random numGenerator = new Random(); 
    private ArrayList<Double> list = new ArrayList<Double>(10_00_000); 
 
    AThread(String name) { 
        this.name = name; 
    } 
    public void run() { 
        for (int i = 0; i < 10_00_000; i++) { 
            list.add(numGenerator.nextDouble()); 
            System.out.println("Allocated : " + name + "[" + i + "]"); 
        } 
    } 
} 
public class TestFlightRecorder { 
    public static void main(String... args) throws Exception { 
        for (int i = 0; i < 500; i++) { 
            new Thread(new AThread("Thread" + i)).start(); 
        } 
    } 
} 

Let's execute ...

Get Java 11 and 12 - New Features now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.