Java mail agent thowing exception

Posted on 2004-08-11
Medium Priority
Last Modified: 2013-11-16

I have a problem with a mail agent written in java. It is used for sending mails for pending items.  The agent is scheduled for every 15 minutes. The number of  pending records are between 50-120 per day.  The code was working fine in the production server for 3 months. But one month back it started throwing "lotus.domino.notes exception" and the application hangs every two days. From the log I couldn't get more details of the error.

My code is pasted below, where've I gone wrong? Could anyone help me.?

Thanks in advance


import lotus.domino.*;

public class JavaAgent extends AgentBase {

      public void NotesMain() {

            try {
                  Session vNotesSession = getSession();
                  AgentContext vNotesAgentContext = vNotesSession.getAgentContext();

                  Document vNotesDocument;
                      DateTime now = null;
                  boolean bSent = false;
                  String sErrorMessage = "";
                  now = vNotesSession.createDateTime("today");
                  Database vNotesDatabase = vNotesAgentContext.getCurrentDatabase();
                  View vNotesView = vNotesDatabase.getView( "ScheduleMailForPending" );
                  View vSettingsView = vNotesDatabase.getView("AppSetting");
                  Document vSettingDoc = vSettingsView.getFirstDocument();
                  String sSupervisor = null;
                  int sPendingHrs = 0;
                  int sUnattendHr = 0;
                  boolean stopMail = false ;
                  String     status = null;
                  String statusFlag = null;
                  if (vSettingDoc != null) {
                          sSupervisor = vSettingDoc.getItemValueString("SetupSupervisor");
                          String sUnattendHrs = vSettingDoc.getItemValueString("SetupUnattended");
                          String sPendingHr = vSettingDoc.getItemValueString("SetupPending");
                        if (sPendingHr != null)
                              sPendingHrs = Integer.parseInt(sPendingHr.trim());
                          String stopM = vSettingDoc.getItemValueString("SetupStopMail");
                         boolean sm   =  (stopM != null && stopM.equals("false") );
                          if (sm && sPendingHrs != 0 && sSupervisor != null)
                            stopMail = true;
                  } else {
                        stopMail = false;
                  //loop through all the documents in the All view and mail them and then remove them
                  vNotesDocument = vNotesView.getFirstDocument();
                  Item tempItem = null;
                  int noOfHours = 0;
                  DateTime tempDate = null;
                   String ticketNo = null;
                  int counter = 1;

                  while ( stopMail && vNotesDocument != null) {
                          status = vNotesDocument.getItemValueString("Status");
                          ticketNo = vNotesDocument.getItemValueString("LogCallTicketNo");
                          Document vDominoDocument = null;
                      try {                            
                              tempItem = vNotesDocument.getFirstItem("AttendDate");
                              tempDate = tempItem.getDateTimeValue();
                              noOfHours = now.timeDifference(tempDate);
                              if (noOfHours > 0 && (noOfHours/3600) >= sPendingHrs) {
                                      vDominoDocument = vNotesDatabase.createDocument();
                                      vDominoDocument.replaceItemValue("Subject", "HelpDesk Application : Pending Calls");
                                      vDominoDocument.replaceItemValue("Body", "This mail has been originated by Helpdesk Application. Call is pending for more than " + sPendingHrs + " Hours \n Ticket Numer is " + ticketNo);
                                      vDominoDocument.send(false, sSupervisor);
                                      bSent = true;
                              } else {
                                      bSent = false;
                      } catch (Exception ex) {
                              bSent = false;
                              System.out.println("Exception " + ex.getMessage());
                      } finally {
                              //Complete fields on the mail document.
                              if ( bSent ) {
                                      vNotesDocument.replaceItemValue("StatusFlag", "Escalated");
                                      vNotesDocument.replaceItemValue("EscalatedStatus", "None");
                                      vNotesDocument.replaceItemValue("MessageStatus", now  + " : Message Sent Ok!");
                                      vNotesDocument.save ( true, false, false );
                      } //try inside while loop                          
                      vNotesDocument = vNotesView.getNthDocument( counter );
                  } //while loop
            } catch(Exception e) {
Question by:joj_123

Author Comment

ID: 11771583
If  I change the frequency to 5mins the application hangs every day. Is it because I've missed out "vnotesDocument.recycle()" method after ".save " method in the finally block?

LVL 46

Expert Comment

by:Sjef Bosman
ID: 11771912
You say several things:
1. the agent used to work (3 months production, no problems)
2. now, the agent comes with errors in the log
3. somehow, you assume it's your code

I think that thinking #3 is jumping to conclusions, but only if you haven't touched the agent in the meantime, of course. Let's do this step by step:
1. what caused the sudden change in the agent's execution, why are there errors?

When you know this, we'll have a clear picture if it has always been your agent or that there might be something else in the environment that caused the problem. It is more than likely that there was an upgrade of the server or some other change in the server's configuration.
LVL 46

Accepted Solution

Sjef Bosman earned 75 total points
ID: 11771962
By the way, are documents automatically removed from the view ScheduleMailForPending when mail is sent out? I strongly advise you NOT to use GetNthDocument in this case, but do the following:
               vNotesDocument = vNotesView.getFirstDocument();
               while ( stopMail && vNotesDocument != null) {
                   vNextDocument= vNotesView.getNextDocument(vNotesDocument);
... // your processing
                   vNotesDocument= vNextDocument

This way, you'll get the next document BEFORE it is removed from the view.
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 24

Assisted Solution

HemanthaKumar earned 150 total points
ID: 11773012
I had similar problem like this (but different error about memory leak) with scheduled java agents.. and soln --- you have to recycle notes objects when done to avoid any memory leaks...

This will improve performance and avoid any errors like this one.


LVL 31

Assisted Solution

qwaletee earned 150 total points
ID: 11773669
Yes, you do have to recycle, but usually, if you don't, it is the SERVER that will eventually run out of heap, not just your agent.  Recycle tells the underlying core C API program (DLL's) that it no longer needs to hold onto the memory used by the Java program, becaause JNI sucks in managing that.

I've found that you have to be careful of the exact order you recycle.  If you process docs in a loop, and use one doc to get the next doc, then you need to get the second before recylcing teh first, which means you need two variables (current doc, next doc, then recycle current, then get next).

Author Comment

ID: 11781115
Thanks a lot everybody. Just after posting the question I came across two useful links which illustrates the importance of the recycle method.(infact we were using the recycle method everywhere in the code, but missed out in this particular agent)

The links are,

http://www-10.lotus.com/ldd/sandbox.nsf/ecc552f1ab6e46e4852568a90055c4cd/afc77a0cb5e49e3a85256a76006b5183/$FILE/JMP106.pdf    (page 20-26)


I've added the recycle method in the agent and awaiting its result.

LVL 46

Expert Comment

by:Sjef Bosman
ID: 12367477
I'd love to learn what the real solution was to the problem...

Author Comment

ID: 12368987
Sorry, I made a mistake while selecting the answers. Assisted answers are supposed to be the accepted ones and vice versa.

The recycle method worked. I had added a method to my controller servlet, which was accessed by everypage, on which I left the session without recycling.

Thanks everybody, for your help.


Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For Desktop Techs: How to retain a user's Notes configuration data when swapping out the end user's computer. (Assuming that you are not upgrading to a completely different version of Notes client) All you need to do is: 1) install Notes o…
I thought it will be a good idea to make a post as it will help in case someone else faces these issues. I trust this gives an idea how each entry in Notes.ini can mean a lot for the Domino Server to be functioning properly. This article discusses t…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question