JNDI connections not closing, remember to close those NamingEnumerations!

I just got off a conference call with a customer who had spent a lot of time debugging a JNDI problem where they would call Context.close() but yet they would still see that their connections were left open. The only way for them to get the connections released were by restarting the VM.

The problem was that the customer had a NamingEnumeration in use, and had never closed it. As per the JNDI docs,

If the Context instance is sharing a connection with other Context and unterminated NamingEnumeration instances, the connection will not be closed until close() has been invoked on all such Context and NamingEnumeration instances. [http://java.sun.com/products/jndi/tutorial/ldap/connect/close.html]

Now remember, even if you don't do a close, the GC will eventually kick in and clean up the Context and NamingEnumeration, but until then your connections will be open. Plus, that's just wrong, be tidy and close your connections properly.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

moazam

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today