tomcat memory utilization,

V

vinodhsri

Hi,

My servlet has compute bound as well as memory bound operation to
perform. Hence, i am creating and starting a thread in my servlet
instead of servlet implementing Runnable. The implementation seams to
work without any problem but the tomcat's memory seams to grow
everytime this servlet instance is called upon.

For example, a single thread utilizes approximately 700MB of memory.
When 3 such threads are run, tomcat process memory increases to 2GB(I
have increased my tomcat memory to 3GB for multiple client's
capability).My gut feeling is I am missing some deallocation part of
executing thread memory or probably the garbage collection is not
working correctly.

I am expecting a behavior where the memory gets deallocated every time
a thread completes. As in the above case, I am expecting tomcat's
memory utilization to retrun back its base minimal

Just as a proof of concept, here is the skeletal code of how the above
explained scenario works.

// Thread code - this is just a mocked up case and not the real code.
The dataset(); allocates a huge chunk of memory but upon the threads
completion the memory is still retained by the tomcat process

public class TestMemoryAnalysis implements Runnable{

private Thread thread;

public TestMemoryAnalysis () throws Exception{
thread = new Thread(this, "test memory analysis");
thread.start();
}

public void run(){
try{
dataset();
System.out.println("AnalysisComplete");
}
catch(Exception e){
System.out.println("In the run exception ioe");
e.printStackTrace();
}
}

// this method is to mimic the memory leaking implementation of the
real code
public void dataset(){
int count=14000;
double[][] array = new double[count][count];

for(int i=0;i<count;i++){
for(int j=0;j<count;j++){
array[j]=i*0.01;
}
}
System.out.println("done creating dataset");
}





//Servet implemtation

public class TestMemory extends HttpServlet{

public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException{
try{
TestMemoryAnalysis am = new
TestMemoryAnalysis();
PrintWriter writer = response.getWriter();
am.start();
writer.write("Done with the analysis");
}
catch(Exception e){
e.printStackTrace();
}
}

public void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException{
doGet(request, response);
}
}

can i get some help on this.
thanks
sri
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top