Results 1 to 4 of 4

Thread: MimeMessagePreparator thread safe issue

  1. #1
    Join Date
    May 2005
    Posts
    23

    Default MimeMessagePreparator thread safe issue

    Please correct me if I am wrong. It seems to me that it is not possible to implement a thread safe MimeMessagePreparator. Because MimeMessagePreparator only has one method:

    Code:
    public void prepare(MimeMessage msg) throws Exception
    most of the configurations and email data (I use Velocity template as my email template) have to be set to preparator's instance variables. That makes it not thread safe. My goal is to have only one JavaMailSender and MimeMessagePreparator to serve all email notifications throughout my application so that I can inject them into controllers or service classes. Maybe the method signature should be changed to:

    Code:
    public void prepare(MimeMessage msg, String from, String to, String subject, String template, Map data) throws Exception
    Any comments?

    Kenny

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Kenny,

    The use of fields does not necessarily make a class unsafe for multi-threading. If those fields are only used as read only data after construction then you should not encounter any problems with theading.

    Likewise, if you have some writable state that is thread-safe (like Hashtable) then you won't have any problems.

    Rob
    Rob Harrop
    Lead Engineer, dm Server
    SpringSource
    http://www.springsource.com

    Co-Author - Pro Spring

  3. #3
    Join Date
    May 2005
    Posts
    23

    Default

    Rob,

    Thanks for your reply. Unfortunately, some of the message configurations (like To, Subject, and velocity template URL) require to be configured at runtime based on client's requests. These are string fields which make the preparator unsafe for multi-threading. How to deal with these fields?

    Kenny

  4. #4
    Join Date
    May 2005
    Posts
    23

    Default

    Rob,

    Just ignore my last post. I didn't think at all when I read your reply. Stupid me!!!

    Thanks again!

    Kenny

Similar Threads

  1. Workaround for BeanUtils Issue in Spring??
    By tdanecito in forum Container
    Replies: 4
    Last Post: Apr 5th, 2006, 02:26 PM
  2. Replies: 5
    Last Post: Aug 11th, 2005, 02:38 AM
  3. Service layer design issue
    By raz0red in forum Data
    Replies: 2
    Last Post: Apr 17th, 2005, 07:23 AM
  4. PageCompononentListener Hooks...JIRA issue?
    By amcauley in forum Swing
    Replies: 9
    Last Post: Apr 15th, 2005, 06:10 AM
  5. Replies: 3
    Last Post: Dec 8th, 2004, 10:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •