ColinMc
ColinMc

Reputation: 1238

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.

Upvotes: 1

Views: 1860

Answers (2)

ColinMc
ColinMc

Reputation: 1238

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.

Upvotes: 0

Andres Olarte
Andres Olarte

Reputation: 4380

Is glassfish keeping the connection open? or the thread running? They are different things. Threads might be started, and not shutdown to service new connections in the future. That's standard behavior. Can you take a thread dump using "kill -3 PID", where PID is the process id of the glassfish process? This will dump all of the running thread to standard output, and you can see what each thread is doing. There you'll be able to see if it's stuck in your code or waiting for a new connection. You can find more info here on how to get a thread dump.

Upvotes: 1

Related Questions