Nuri Ensing
Nuri Ensing

Reputation: 2030

Keeping databases open in Java agent IBM Domino / Lotus

I have a Java agent. When I run the agent I also create a object which is opening databases. This is the code of the databases class:

public class Databases {
    Database OrdersDB;
    Database CustomersDB;
    Database ItemsDB; 
    Database TablesDB; 
    Database ItemsDB;

    public Databases() throws NotesException{
    }

    public boolean openAllDatabases(Session session){

        try {

            OrdersDB = session.getDatabase(getServerName(session,"ORDER"),globalSettings.OrderDB, false);
            CustomersDB= session.getDatabase(getServerName(session,"CUSTOMER"),globalSettings.CustomerDB, false);
            TablesDB= session.getDatabase(getServerName(session,"TABLES"),globalSettings.TablesDB, false);
            ItemsDB = session.getDatabase(getServerName(session,"ITEMS"),globalSettings.ItemsDB, false);
            return true;
        } catch (NotesException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            System.out.println("Database not opened!");
            return false;
        }

    }

Throughout the agent I use this Database obj. Also in my agent I create another class in which i pass this database obj as parameter and also use the databases there. Finally when my agent is done I recycle all the databases and set the database Obj to null.

I wonder if this a good practice to do? I already tried to open and close database whenever needed but because the code is to big I will get null pointer exceptions if I wrongly for example recycled the database in another class. Thats why I keep open the databases at the start of the agent and recycle them at the end. But I do not know if this causes memory leaks.

Upvotes: 1

Views: 76

Answers (1)

Knut Herrmann
Knut Herrmann

Reputation: 30960

Don't worry about not recycling databases. When the agent is finished all databases will recycled automatically.

It is only important to recycle Domino object if you instantiate those by hundreds or thousands like running through all entries in a view.

Upvotes: 2

Related Questions