Results 1 to 4 of 4

Thread: Is LdapTemplate thread safe?

  1. #1
    Join Date
    Nov 2005
    Posts
    13

    Default 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. #2
    Join Date
    Mar 2005
    Location
    Landskrona, Sweden
    Posts
    505

    Default

    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.
    Mattias Arthursson
    Jayway AB (www.jayway.se)
    Spring-LDAP project member

  3. #3
    Join Date
    Jul 2009
    Posts
    2

    Default

    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

  4. #4
    Join Date
    Jul 2009
    Posts
    2

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •