Deploy this Web Application on any of the Server in a Domain and access the index.jsp, click on submit button, open sending the request the server would generate OutOfMemory Error.
index.jsp
<html>
<head>
<title>Request Page</title>
</head>
<body>
<form action="firstrequest">
<table border="0" align="center">
<tr><td colspan="2" align="center">Welcome Testing Servlet</td></tr>
<tr>
<td align="center">
First NAME : <input type="text" name="HOSTNAME">
</td>
<td align="center">
Second NAME : <input type="text" name="instancename">
</td>
</tr>
<tr>
<td align="center" colspan="2">
<input type="submit" name="button" value="Click">
<input type="submit" name="button" value="Close" onclick="window.close()">
</td>
</tr>
</table>
</form>
</body>
</html>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<servlet>
<servlet-name>application</servlet-name>
<servlet-class>Sample</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>application</servlet-name>
<url-pattern>/firstrequest</url-pattern>
</servlet-mapping>
</web-app>
Sample.java
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Sample extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
System.out.println("Entering servlet............");
try {
MemoryLeak ml = new MemoryLeak();
ml.createObjects();
} catch (Exception e) {
e.printStackTrace();
}
}
}
MemoryLeak.java
import java.util.*;
public class MemoryLeak {
private static List<Integer> memoryLeakArea = new ArrayList<Integer>();
public void createObjects() throws Exception {
while (true) {
Integer count = new Integer("0");
memoryLeakArea.add(count);
Thread.sleep(10000);
}
}
}
great
ReplyDelete