Java agent: send a memo doc in loop crashes

I have this java agent for testing( see code below). The agent completes fine, if (x<1) is specified in the for loop condition. But if I make it loop twice, then the agent (run on local designer client) seems to hang. Both messages recieved fine, but in the agent log, logging never reaches the “end” line. No error, since agent is running on local machine, the java console is always empty after I restart client…

I am new to java, so can you spot anything obviously wrong here? many thx in adv

import lotus.domino.*;

public class TestSendMemoInLoop extends AgentBase {

Session s;

AgentContext ac;

Database db;

Document memo;

Log log;

String m = new String();



public void NotesMain() {

	try {

	s = getSession();

	ac = s.getAgentContext();

	db = ac.getCurrentDatabase();

	log = s.createLog("TestSendMailInLoop in " +				      db.getTitle() + " on " + db.getServer());

log.openNotesLog(null, "alog4.nsf");

		log.logAction("started");

		for (int x=0; x < 2; x++) {

			

			memo = db.createDocument();

			memo.replaceItemValue("Form", "Memo");

			if (x==0)

				m="A";

			else

				m="B";

			memo.replaceItemValue("Subject", "send email in loop" + m);

			

			memo.replaceItemValue("SendTo", "Xun.Dong@thomasmiller.com");

			

			memo.setSaveMessageOnSend(true);

			boolean suc = memo.computeWithForm(true, false);

			

			log.logAction("about to send memo " + memo.getItemValueString("Subject"));

			memo.send();

			

			memo.recycle();

			//memo=null;

			

		}

		if (memo!=null) 

			memo.recycle();

		if (db!=null)

			db.recycle();

		if (ac!=null) 

			ac.recycle();

		if (s!=null)

			s.recycle();

		log.logAction("end");

		System.out.println("Testsendmemoinloop ended");

	} catch (NotesException ne) {

		

		ne.printStackTrace();



	} catch (Exception e) {

		e.printStackTrace();



	}





}

}

Subject: solutaion found!

After I tried to run the agent on server, it actually then logged error to the server log.

It was nothing to do with the send method, but object memo was recycle() at the bottom of the loop, so when it comes round again, it didn’t like the if statement checking the recycled object…

doh!

Subject: RE: java agent: send a memo doc in loop crashes

Done some more test on the above agent:Changed the .send(False) to .save(True, false)

So saving the memo in the loop works fine. but not .send method.

why, …

is there any known problem with this method called in loop?