Hi,
I want to create a singleton for DirContext for LDAP configuration, hence i have used the initialize on demand
class holder idiom as shown below
public class SlmApplicationContext {
/**
* inner class to hold the instance.
*/
private static class Holder {
private static DirContext instance =
new InitialDirContext();
}
/**
* Method to get the singleton instance of this class.
* @return SlmApplicationContext
*/
public static SlmApplicationContext getInstance() {
return Holder.instance;
}
...
}
Now the problem is if i close the DirContext.close(), when the next request comes the singleton wont
work as the dir context is already closed, hence it will create a new dir context for each requests.
Which breaks the singleton concept, hence how we can ensure the singleton works fine even with DirContext.close()?
Please clarify.
Thanks.