Hi,

Jay SenSharma

Jay SenSharma

As a Debugger or a Support Engineer most of the time we need to reproduce many issues to test our Product/Application/Envs. Sometimes we need to generate “High CPU” or “Natiive OutOfMemory” scenarios sothat we can see the Stability of our Product…So here is a Simple demonstration to generate these kinds of fancy stuff …sothat whenever it is needed we can add/modify these codes to suit our actual requirement.


This Program really be helpful for those who want to Learn Thread Dump Analysis …to identify that which thread Causes the High CPU…So just use the below program to generate High CPU and take few Thread Dumps at that time…then start Analyzing them…sothat..when the real High CPU occurs you can easily identify …which Application Thread/ Server Thread/…Causes this issue.

The following program generates a High CPU load…the code written inside the main() can be written inside the “serlet” or “jsp” pages…in order to generate HighCPU from inside the WLS Container…as well

“CPULoadGenerator.java”

public class CPULoadGenerator
{
public static void main(String[] args)
{
for (int i=0; i < 3; i++)
{
new Thread(new Runnable()
{
@Override
public void run()
{
System.out.println("Thread " +Thread.currentThread().getName() + " started");
double val=10;
for (;;)
{
Math.atan(Math.sqrt(Math.pow(val, 10)));
}
}
}).start();
}
}
}

———————

Thanks
Jay SenSharma

If you enjoyed this post, please considerleaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.