DZone

In this series of chaos engineering articles, let’s discuss how to simulate CPU consumption to spike up to 100% on a host (or container). CPU consumption will spike up whenever a thread goes on an infinite loop. Here is a sample program from the open-source BuggyApp application, which would cause the CPU to spike up.

public class CPUSpikeDemo {   

  public static void start() {    
     new CPUSpikerThread().start();    
     new CPUSpikerThread().start();    
     new CPUSpikerThread().start();    
     new CPUSpikerThread().start();    
     new CPUSpikerThread().start();    
     new CPUSpikerThread().start();    
    System.out.println("6 threads launched!");  
 } 
}
 public class CPUSpikerThread extends Thread {   
  
  @Override  
  public void run() {             

    while (true) {                  

    // Just looping infinitely    
   }  
  } 
}

Source: DZone