- Thread Testing Program

This section describes a thread testing programs,, that keep adding new thread in a while loop.

To find out the maximum number of threads we can run, I wrote the following program:

 * Copyright (c) All Rights Reserved.
import java.util.*;
import java.text.*;
class CrashThread2 extends Thread {
   public static void main(String[] arg) {
      Thread t;
      int m = 32;
      if (arg.length>0) m = Integer.parseInt(arg[0]);
      Date now;
      DateFormat df = DateFormat.getTimeInstance();
      Runtime rt = Runtime.getRuntime();
      System.out.println("Time   Threads   T.Memory   F.Memory");
      for (int n=1; n<=m; n++) {
         now = new Date();
         t = new CrashThread2();
         long tm = rt.totalMemory()/1024;
         long fm = rt.freeMemory()/1024;
         System.out.println(df.format(now)+"   "+n+"   "+tm+"   "+fm);
   public void run() {
      while (true);

The program is a simple thread with infinite while loop in the run() method. The main() method is included in the thread to avoid writing another class to launch the thread repeatedly.

Test results on different JVMs are discussed in following sections.

Table of Contents

 About This Book

 JVM (Java Virtual Machine) Specification

 Java HotSpot VM - JVM by Oracle/Sun

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 JVM Runtime Data Areas

 JVM Stack, Frame and Stack Overflow

Thread Testing Program and Result - Thread Testing Program

 Thread Test on HotSpot JVM 10

 Thread Test on HotSpot 1.7

 Thread Test on JRockit 28.7

 Thread Test on HotSpot 1.4 and JRockit 7.0

 Thread Test on HotSpot 1.6

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 OpenJ9 by Eclipse Foundation

 JRockit JVM 28.2.7 by Oracle Corporation

 Archived Tutorials


 Full Version in PDF/EPUB