Hi,

I have bit strange memory problem. I wrote a java application that uses
standalone Turbine to
send emails using qmail. I have chosen turbine standalone to use different
services, importantyly
TurbineVelocity.

I have to call TurbineVelocity.handleRequest method in a loop to send
several emails using qmail.

This application seems to have memory problems and ultimately crashing due
to out of memory.

I tried to find out the memory used (using java.lang.Runtime) and figured
out that if I comment
TurbineVelocity.handleRequest call there was no memory leak at all. I have
to use this call 500,000 times
in a loop.

I am using TDK 2.1.

Any suggestions are much appreciated

Thanks,
Aravinda

My code looks like this:

// Turbine
import org.apache.velocity.context.Context;
import org.apache.turbine.util.TurbineConfig;
import org.apache.turbine.services.resources.TurbineResources;
import org.apache.turbine.services.velocity.TurbineVelocity;
import org.apache.turbine.Turbine;
import org.apache.turbine.util.Log;
import org.apache.turbine.util.ServerData;
import org.apache.turbine.util.template.TemplateLink;
import org.apache.turbine.util.db.pool.DBConnection;
import org.apache.turbine.services.db.TurbineDB;


//My imports here



/**
 * Application to stream emails to customers using qmail-inject
 *
 * @author Aravinda
 * @version 0.1
 */
public class SendBulkMails
{


   public SendBulkMails() throws Exception
   {
      //SOME OTHER CODE

      //Initializing turbine
      TurbineConfig tc = new TurbineConfig(".",
"conf/TurbineResources.properties");
      Turbine turbine = new Turbine();
      turbine.init(tc);


   }


   public static void main (String args[])
   {
      try
      {
         long before;
         long after;
         float time;

         // Create a stream to the log file
         FileOutputStream fo = new FileOutputStream("logs/timer.log");
         PrintStream ps = new PrintStream(fo);

         // Initliase turbine

         SendBulkMails mail = new SendBulkMails();


         // Get the context
         Context context = TurbineVelocity.getContext();

         before = System.currentTimeMillis();

         int i = 0;


         while(i < numberOfUsers)
         {

                customer        = new Customer();
                //Other objects

                context.put("Customer" , customer);

                //increment mail count
                i++;

                ps.println("Used Mem : " +
(java.lang.Runtime.getRuntime().totalMemory() -
java.lang.Runtime.getRuntime().freeMemory()));

                //send template output to System.out

                TurbineVelocity.handleRequest(context, sEmailTemplate,
System.out);

                System.out.print("\n\n");


                context.remove("Customer");

                //TurbineVelocity.requestFinished(context);

                customer = null;
                //other objects = null;

           }


         after = System.currentTimeMillis();

         time = (after - before) / 1000f;

         ps.println("-- Sent " + i + " emails in " + time + " seconds! --");


         // Close the log stream
         ps.close();
         fo.close();
      }
      catch(Exception e)
      {
         //Log error and exis
            System.exit(1);

      }
   }

}



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to