title: Spring MVC email mail sending using Queue model
body: <p>I have a scenario in which, I need to start a thread when the container starts and stops while the container stops. I am using Spring MVC for my application. My end-goal is to send an email when user performs a particular action. Moreover I don't want to slow the flow due to the email sending process. So what I am planning is that, I will create a queue and put the mail message in the queue whenever I need to send out a mail. A thread which is started during  the start-up will read the queue and send-out the mail. Here I am facing two problems:</p>
  
  <ol>
  <li>How can I start and stop a thread when application starts/stops(For normal web application, I can make use of ServletContextListener for this.) in the case of Spring MVC?</li>
  <li>In the thread, I need to call a mail service to send-out the mail. So how can I inject the service to the thread? Is it possible? </li>
  </ol>
  
  <p>Any tip or more flexible solution is highly appreciated....</p>
  
  <p>~Ragesh</p>