Demonstration of recycle method in designer help is fairly simple but how to use efficiently in little complex classes. Here is simple example,

Places where I've used recycle method is commented with "my assumptions".Let me know my mistakes or suggest me better way to design classes.

JavaAgent.java
--------------------------------------------

import lotus.domino.*;

public class JavaAgent extends AgentBase
{


public void NotesMain() {

try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
...
Animal cat= new Animal(session);
cat.findDetails(session);

/* my assumptions */
session.recycle();
db.recycle();
/*-------------*/
}
catch(Exception e) {
e.printStackTrace();
}
}
}


Animal Class
-----------------------------------------------

import lotus.domino.*;
import java.sql.*;

public class Animal {

/* find details method */
public String findDetails(Session session) throws Exception
{
try{


Database A= session.getDatabase(db.getServer(), "A");
getCatFromDb("A");
removeCat();
...
/* my assumptions */
conn.close(); //created in constructor
stmt.close(); // created in getCatFromDb
rs.close(); // created in getCatFromDb
A.recycle(); //created in findDetails
db.recycle(); // created in constructor
/*----------*/
}
catch(Exception e)
{

e.printStackTrace();
}
}

/* Start Constructor */
Animal (Session session)throws Exception {
try {
AgentContext agentContext = session.getAgentContext();
db = agentContext.getCurrentDatabase();
conn=...external driver...
...some stuffs from db...
Document doc = db.getProfileDocument("config","");
...some stuffs from doc...

...jdbc connection here...
...
}
catch(Exception e)
{

e.printStackTrace();
}
}
// end Constructor

/* getCatFromDb method */
public void getCatFromDb(Database dbPath){
try{
View v=dbPath.getView("A");
if(v!=null)
{
Document doc= v.getFirstDocument();
while (doc != null)
{
..some stuffs from external db like
creating statement,recordset etc ...

doc = v.getNextDocument(doc);
}
}
}catch(Exception e){e.printStackTrace();}
}
public void removeCat() {

// some stuffs here..

}

}

2 Responses to "How to use recycle method in Domino Java efficiently ?"

  1. gravatar Rishi Says:

    One good suggestion I got from my previous post is to recycle document while looping..Here is an example,

    Document doc= v.getFirstDocument();
    Document tdoc=null;

    while (doc != null)
    {
    ..some stuffs

    tdoc=v.getNextDocument(doc);
    doc.recycle();
    doc=tdoc

    }

  2. gravatar sree Says:

    Rishi, Here is one thought....finally block will execute all the time once completed the main function.

    public class JavaAgent extends AgentBase
    {
    //declare variable here
    private Session s=null;
    public void NotesMain() {

    try {

    }catch(){
    }finally{
    try{
    //recyle domino objects here
    if(s!=null) s.recycle();
    or call recycle function here
    }catch(){
    }
    }

    thanks,
    Sreedhar
    www.thesolos.net

Leave a Reply

preload preload preload