JVM Tutorials - Herong's Tutorial Examples
Dr. Herong Yang, Version 4.10

Thread Testing Program

This section describes a thread testing programs and test results with HotSpot Client VM and HotSpot Server VM.

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

/**
 * CrashThread.java
 * Copyright (c) 2002 by Dr. Herong Yang, herongyang.com
 */
import java.util.*;
import java.text.*;
class CrashThread extends Thread {
   public static void main(String[] a) {
      Thread t;
      int m = 16;
      Date now;
      DateFormat df = DateFormat.getTimeInstance();
      for (int n=1; n<=m; n++) {
      	 now = new Date();
         t = new CrashThread();
         t.start();
         System.out.println(df.format(now) + " Launched thread "+n);
      }
   }
   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. The program was compiled with J2SDK 1.4.0_02, and executed with the same memory options: -Xms2m -Xmx64m.

Output on JRockit JVM:

10:28:21 AM Launched thread 1
......
10:28:22 AM Launched thread 16

Output on HotSpot Client:

10:30:06 AM Launched thread 1
......
10:30:09 AM Launched thread 16

Output on HotSpot Server:

10:31:56 AM Launched thread 1
......
10:31:58 AM Launched thread 16

As you can see, all 3 JVMs had no problems launching 16 threads, and kept them running. Note that all threads are user threads by default. They continue to run even after the calling threads has been terminated.

When I increase the number of threads to 32, the executions were getting interesting:

  • JRockit JVM: After launched 32 threads, the system was getting very sluggish. The mouse pointer were very much alive, but any mouse click would take about 30 seconds for the system to respond. I was able to end the JVM process by the system task manager.
  • HotSpot Client and Server: After launched 32 threads, the system basically got jammed. Only the mouse pointer can be moved around. No response to any mouse clicks. I had to turn off the power to restart the system.

I guess the problem was in the operating system (Windows 2000). It failed to treat the running JVM process as one single process event it had 32 threads running inside. The operating system should be able to put the JVM process in wait mode when its CPU time share is used up, and process my mouse clicks before returning back to the JVM process. Could some one verify this on a UNIX system?

Last update: 2002.

Table of Contents

 About This Book

 Download and Install Java SE 1.6 Update 2

 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 7.0 by BEA Systems

 JRockit JVM 8.0 by BEA Systems

 Memory Management Rules and Tests

 Garbage Collection Tests

 Stack Overflow Tests

Thread Testing Program and Result

Thread Testing Program

 Thread Testing Result with JDK 1.6.0

 StringBuffer Testing Program and Result

 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

 References

 PDF Printing Version

Dr. Herong Yang, updated in 2010
Thread Testing Program