Search code examples
javalinuxservletsglassfish-3

Glassfish not closing threads when done request


I have a Java Servlet that has a doPost method and when the doPost finishes, I assumed Glassfish would close the connection, but I was wrong. The Servlet is on a Linux server and after 300 posts the thread count returned:

ps -eLFU glassfish | grep domain1 | wc -l
362

Before any posts, the thread count was 72. The responses are all successful but I do not understand why Glassfish is not closing the connections. I am using the default configurations for Glassfish.

The reason I am trying to solve this problem is when my servlet is being hit at some point I get this error on the Linux server:

su: cannot set user id: Resource temporarily unavailable

In the /etc/security/limits.conf I have this:

glassfish hard nproc 4192
glassfish soft nproc 2024

I do not want to update the limits.conf but instead try to make sure it does not reach those numbers.


Solution

  • Found the problem it was a code issue. The servlet uses a client to make a call to a web service and the client needed to be a singleton. Originally I was creating a client per POST to the servlet, which created a lot of threads under glassfish. Once I made the client a singleton the thread count went down a lot.