• Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaMail in multithreaeded environment

 
swap Inam
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have a mail program which is using JavaMail API 1.4ea
It is configurable for number of threads to be used for sending outgoing mails. When there is only one thread for sending outgoing mail, program works fine. When there are multiple threads, say, 2,3 or 4, for sending outgoing mails, few of the mails are lost. For e.g. If 100 outgoing messages are sent, only 97 are received in Outlook Express.
Anybody has encountered this scenario or aware of what could be the cause ?

There are following cases to be considered
(1) Is there any setting on Exchange Server for this ?
(2) Tried with different mail clients but still messages received are less than messages sent.
(3) When Logs are enabled using "-Dmail.debug=true" and "logging.properties" file, the Log shows all the messages as sent

Could anybody throw some light on this ?
Any comments will be greatly appreciated.

Thanks
Swapnil
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exchange would be a pretty lousy server it it couldn't handle multiple simultaneous incoming connections.

An intermediate step to investigate would be to check if Exchange actually received all messages.
 
swap Inam
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf

Thanks a lot for your response.

Yes, will sure verify if exchange is receiving all the messages.

BUT, still have a query, why it works with single thread and doesn't
in multithreaded mode when the Log file shows no exceptions/error and
exactly the same number of emails sent as is expected ?

How the email clients end up receiving exact number of mails as were sent with single sender thread and less when multiple threads are used ?

Would greatly appreciate your comments

Thanks a lot
Swap
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by swap Inam:
why it works with single thread and doesn't
in multithreaded mode when the Log file shows no exceptions/error and
exactly the same number of emails sent as is expected ?


That's what you're trying to figure out by checking whether or not Exchange actually received the messages. If it did receive 100 messages, then JavaMail worked OK, and there shouldn't be any error messages in the JavaMail logs, because the problem lies with Exchange or Outlook.
[ August 01, 2007: Message edited by: Ulf Dittmer ]
 
swap Inam
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ulf,

Thanks once again for the response.

Checked on the exchange server and it doesn't receive all the messages.

It seems the problem is with the message id's, in case of multiple threads,
the JavaMail method getMessageID() in MimeMessage, returns same message id
for multiple messages and that's how we end up loosing mails.

Any ideas on how to solve this or any comments

Your comments are greatly appreciated.

Regards and Thanks a lot
Swap
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you possibly reusing objects you shouldn't be reusing? Or using objects that are not thread-safe in multiple threads? The rule of thumb is that if the javadocs don't mention that an objetc is thread-safe, then it shouldn't be considered thread-safe.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!