Discussions

Web tier: servlets, JSP, Web frameworks: Mass email sending process on separate thread in web app

  1. Hi I'm not sure if it's proper forum for this question, so sorry in advance if not. I need to make as a part of web page the system for sending newsletters to many customers (>30k). What I need is a hint what to use to get mail sending process working independend on web app. So, user clicks "Send" and can work with other things on the page.. I tried some things but everything just waits for process to finish before navigating to next page.. Michal
  2. What about to create Runner object and run it as a new thread? I've never tried it yet, but maybe should work :)
  3. When the user clicks on send, on the server you can post a JMS message to a particular jndi topic, and you can have a message driven bean to listen and let this bean do the process of sending emails, since jms is asynchronous, you page will not wait, and the user can see the other page immediately. btw. Starting your own thread inside the webapp is not a standard or supported by the spec.
  4. There are actually many ways to do this, JMS is one of them but you are required to install some dependency in the app server if you are using Tomcat only. The other way is to have a simple scheduler, which you can either install Quartz or if you are using Spring, then you already have it. What you can do is to setup the scheduler, create sendEmail as a job and you pass all your emails that you need to send, in the execute() method you program all these. When users submit a request, the request goes to controller, the controller create this job and trigger the scheduler to run this job immediately or after a while or during midnight. Once you submit this job, it will execute the next line in the controller code, which will not hold you back from sending all email.