The LDAP service provider uses this URL to configure its connection to the directory server. Only the host, port, and dn parts of the URL are relevant in this setting. Supplying other parts of the URL results in a ConfigurationException(in the API reference documentation). Most commonly we use just one URL. But we can also supply a space-separated list of URLs. In this case, the LDAP provider will attempt to use each URL in turn until it is able to create a successful connection. How to determine, on which server, are we connected to?? The LDAP provider set Context.PROVIDER_URL property to the successful URL, so that the application can determine which URL is being used. Here is an example of how to specify a list of URLs.
Hashtable env = new Hashtable();
// Specify list of space-separated URLs
env.put(Context.PROVIDER_URL, “ldap://host1:389/o=JNDITutorial ” + “ldap://host2:389/o=JNDITutorial ” + “ldap://host3:389/o=JNDITutorial ” + “ldap://host4:389/o=JNDITutorial”);
// Create initial
context DirContext ctx = new InitialDirContext(env);
// See which server was used