Announcement Announcement Module
Collapse
No announcement yet.
MimeMessagePreparator thread safe issue Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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

    Comment


    • #3
      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

      Comment


      • #4
        Rob,

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

        Thanks again!

        Kenny

        Comment

        Working...
        X