Announcement Announcement Module
Collapse
No announcement yet.
Is LdapTemplate thread safe? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is LdapTemplate thread safe?

    Hi,

    I have to ask this here again, in core nobody knows it

    Is the LdapTemplate class thread safe?

    TIA, sr

  • #2
    Yes, the LdapTemplate class and its collaborators don't hold any state and should be fully thread safe.

    The exeption would be DistinguishedName and its components; modifying the same DistinguishedName in different threads would have undefined behavior, but then again I can't think of any case where that would be desired.

    Comment


    • #3
      While I know this thread is old, I hope that I might get a clarification on something.

      While the LdapTemplate, LdapContextSource and InitialLdapContext may be thread safe, the javax.naming.InitialContext and javax.naming.InitialDirContext that these classes wrap are not thread safe, so multiple threads accessing a single context must be synchronized.

      So, is LdapTemplate etc, synchronized (looking at the source, they don't appear to be) or is there some other synchronization mechanism at play here?

      Lastly, in order to obtain multiple contexts, and given that LDAP contexts are pooled, Would it maybe be more performant to define the LDAP context etc as prototype rather than singleton, so each thread obtains it's own context?

      Thanks in advance
      Steve

      Comment


      • #4
        I think I've answered my own question. LdapContextSource creates a new InitialLdapContext every time a context is required. So the multiple threads should each be using their own DirContext.

        Cheers
        Steve

        Comment

        Working...
        X