CrashThread2.java - Thread Testing Program

This section describes a thread testing programs, CrashThread2.java, 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:

/* CrashThread2.java
 * Copyright (c) 2013, HerongYang.com, 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();
         t.start();
         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.

Last update: 2014.

Table of Contents

 About This Book

 Downloading and Installing JDK 1.8.0 on Windows

 Downloading and Installing JDK 1.7.0 on Windows

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 Sun's JVM - Java HotSpot VM

 JRockit JVM 28.2.7 by Oracle Corporation

 JVM Runtime Data Areas

 Memory Management and Garbage Collectors

 Garbage Collection Tests

 JVM Stack, Frame and Stack Overflow

Thread Testing Program and Result

CrashThread2.java - Thread Testing Program

 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

 Outdated Tutorials

 References

 PDF Printing Version