How to set JNDI properties the right way

I've found that some developers try to set JNDI properties via environment variables and then wonder why their settings don't seem to hold. For example, a developer might create a Hashmap (env) and set their JNDI property value using Hashmap.put(),

public static final String LDAP_CONNECTION_POOL_MAX_SIZE = "com.sun.jndi.ldap.connect.pool.maxsize";
env.put(LDAP_CONNECTION_POOL_MAX_SIZE,"5");

Now the LDAP_CONNECTION_POOL_MAX_SIZE value is definitely set to 5, but Java/JNDI won't honor it and will allow programs to create as many connections as they want.

The reason for this is that JNDI properties \*cannot\* be set via environment from within Java and must be set as System properties using one of the following methods:

1.) Add "-Dcom.sun.jndi.ldap.connect.pool.maxsize=5" to the java command line when running your application.

or

2.) Set the com.sun.jndi.ldap.connect.pool.maxsize as a system property from within your code, i.e.,
System.setProperty("com.sun.jndi.ldap.connect.pool.maxsize", "5");

The documentation which verifies this is at: http://java.sun.com/j2se/1.4.2/docs/guide/jndi/jndi-ldap.html

Section 15.3 Global Configuration

"Connection pooling is configured by a number of System properties at runtime startup time. Note that these are System properties, not environment properties and that they affect all connection pooling requests. "
Comments:

Post a Comment:
Comments are closed for this entry.
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