FreeKB - 0 How to replicate a hung thread in Eclipse
How to replicate a hung thread in Eclipse

This assumes you have created your first dynamic web project in Eclipse. If you have not yet created a package, in the left panel of Eclipse, expand the Java Resources folder, right click on the src folder, and select New > Package. Give the package a name, such as com.main and select Finish. Right click on the newly created package and select New > Servlet. Give the servlet a name, such as HungThread, and select Finish.

If you want the thread to hang indefinitely, in the doGet method section of the markup, add the following.

while(true) {
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}

 

If you want the thread to hang for 13 minutes, in the doGet method section of the markup, add the following.

int count = 1;
while (count < 800) {
  try {   			
    Thread.sleep(1000);
    count++; 
	} catch (InterruptedException e) {
      e.printStackTrace();
	}   		
    out.print("Thread was hung for 800 seconds (13 minutes).");
}

 

Add the following markup to your web.xml file. If your package is something other than "com.main", replace com.main with the name of your package.

<servlet>
   <servlet-name>HungThread</servlet-name>
    <servlet-class>com.main.HungThread</servlet-class>
</servlet>
 
<servlet-mapping>
    <servlet-name>HungThread</servlet-name>
    <url-pattern>/HungThread</url-pattern>    
</servlet-mapping>

 

You can now run the project on your server runtime in Eclipse, or export the WAR or EAR to your application server (JBoss Tomcat WebSphere), and then navigate to www.example.com/context_root/HungThread. The page should load endlessly.



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




Please enter b8ddc in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |