Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Singleton for LDAP DirContext

User_19BPUAug 9 2013 — edited Aug 10 2013

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.

Comments

312396
Hi, Dominic. Your question of whether you should use Oracle Help for Java (OHJ) or Oracle Help for the Web (OHW) is answered by another question that you can hopefully answer yourself. If you want the help content to be installed on the client's machine, then you're best off using OHJ. If you'd like to host the help content on the server, then you ought to use OHW. The great thing about Oracle Help Technologies is that even if you commit to using one of our help systems, you can easily switch over to the other since we use the same help control files for both systems.

You can find out more about Oracle Help by reading the Oracle Help Guide at
http://otn.oracle.com/docs/tech/java/help/htdocs/ohguide/ohg_toc.html

You can deploy OHJ with any Java-based application, and OHW just needs a web browser.

To download OHJ and OHW (they are both free), go to
http://otn.oracle.com/software/tech/java/help/content.html

Hope this helps,
Ryan
1 - 1
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Sep 7 2013
Added on Aug 9 2013
3 comments
1,070 views