• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Mail API

 
Chinmay Bajikar
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does the mail sent thru the Java mail API always go as a seperate asynchronous thread.Also what is there any way, other than synchronization, to hold procesing until the mail has been sent?
 
Joel Peach
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chinmay,
To the best of my knowledge, calls to the Transport.sendMessage() method block until the sending of the message is complete. The primary reason I could see for this is that several exceptions may be generated when the underlying transport actually tries to deliver the message (MessagingException).
(I have only used the SMTP transport implementation provided by Sun, though the JavaMail spec leads me to believe that the message could actually be sent asynchronously. I.e., it's up to the Transport provider)
I actually had an application where I didn't want the method to block, so I wrote a messaging manager that would fire off a new thread for each message to be sent, but registered itself as an "exception handler" to the thread so that any exceptions the thread encountered could be delivered in a queue-like fashion.
To answer your second question, making a call to Object.wait() is the only way I'm aware of to force blocking of threads. However, you would need some way to know when the mail was finished sending so you could call Object.notifyAll(). I don't know that JavaMail provides the means to do there, although if it were anywhere, it would be in the TransportEvent mechanism.
Best of luck!
-Joel
jpeach@traceris.com
Originally posted by Chinmay Bajikar:
Does the mail sent thru the Java mail API always go as a seperate asynchronous thread.Also what is there any way, other than synchronization, to hold procesing until the mail has been sent?

 
Hello World
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good Reply
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!