-----------------------------
Please read the FAQ!
<http://java.apache.org/faq/>
-----------------------------

I've been using OptimizeIt to find a memory leak in one of our servlets and
was able to trace it to a specific object used in one method of the servlet.


For the sake of argument, the object name is WClient.   The object uses a
socket connection to talk to a server application.  I've gotten rid of the
major memory leak by cleaning up all the resources that were being used by
the WClient object.

However, it appears that everytime the servlet runs, there is another thread
created that will not go away, and there is a new instance of the WClient
object.  This seems odd since the WClient object is only used by a single
method, which has code that basically looks like this:

    WClient wc = new WClient(ipAddress_);
    wc.connectToServer();        //establish connection to server
    wc.someMethod(xxx);        //execute some code
    wc.close();                        //close connections, free WClient
resources
    wc = null; 

I expect that there would be no WClient objects allocated, especially since
the WClient referece should be eliminated when the wc variable gets set to
null.  It should go away when the method ends anyway, which obviously
happens since there is other code that is being executed after the method
containing this code returns.

Can anyone think of a reason why a servlet would leave threads hanging out?
It seems like the doGet method must be completely executing, since the html
page it builds is being returned correctly, but I can't figure out why the
threads are hanging and the WClient objects are being left instantiated.
Are there any issues relating to a multi-threaded servlet that I'm missing,
like synchronizing the method that uses the WClient object?  

Even though I've solved the major memory problems,  I don't want  to
endlessly generate all of these threads.

Any thoughts would be appreciated. 

Cary Mader






--
--------------------------------------------------------------
Please read the FAQ! <http://java.apache.org/faq/>
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://java.apache.org/main/mail.html>
Problems?:           [EMAIL PROTECTED]

Reply via email to