java managed server bean crashes

Viewed 71

Why would I not be able to call this multiple times?

 private Document getStationery(String txtStationery,Database mailDB){
      try {
        View mailView = mailDB.getView("(Stationery)");
        DocumentCollection dc = mailView.getAllDocumentsByKey("Memo Stationery");
        Document tmpdoc;
          Document doc = dc.getFirstDocument();
          while (doc != null) {
             if(doc.getItemValueString("MailStationeryName").equals(txtStationery))
            {
                return doc;
            }
            tmpdoc = dc.getNextDocument();
            doc.recycle();
            doc = tmpdoc;
          }
         
    } catch (NotesException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return null;
      
  }

Crashes on second use of it below .... something to do with not recycling?

public void send() throws NotesException, IOException, Exception{
    Session session = getCurrentSession();
    Database userDB = getUserDatabase();
    Database mailbox = session.getDatabase("", "mail1.box");
    Document stationeryDoc1 = getStationery("Test1",userDB);
    Document stationeryDoc2 = getStationery("Test2",userDB);

1 Answers

You could try without recycling at all (generally not a good idea, but here it may be helpful to rule out other problems), or recycle the objects in the getStationary() method properly, beginning with the Document, the DocumentCollection, and finally the View. At the moment, the only object you recycle is the previous Document object in the while loop.

Related