createSession() and recycle() confusion

I’m new to Domino programming in Java. I am trying to update (reconnect) the Notes/Sametime connection at certain intervals. I’m using NotesFactory.createSession(QueueServer, QueueUser, QueuePass) to create the connection and Sess.recycle() to close out a connection. However, if I createSession() while a Session is already open, I get a DuplicateObjectException. If I recycle when there is no session open, I get a NullPointerException. Is there a better way to manage the connection without having to worry about these exception conditions? In particular, I would like a getSession() type method, but one doens’t seem to be available. Any suggestions would be appreciated.

Subject: createSession() and recycle() confusion

Create your own getSession() method that uses a Singleton pattern.

Class MySession {

static Session session = null;

public static Session getSession() {

if (session == null) {

session = NotesFactory.createSession(…); // lazy inialize at first access

}

return session;

}

}

Using the above pattern (bar any bugs tht have sneaked its way in :wink: you will only ever have one Session instance, since it is declared static. And you won’t ever have to recycle it, although you could have a static method MySession.recycle() that recycles the session object. But there is no point in calling the recycle method before the application exits.

So any code may make a call like:

Session session = MySession.getSession()

Subject: RE: createSession() and recycle() confusion

Thank you very much. That helped a lot!

Doug