Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm researching whether Javamail is threadsafe, in particular in a situation with many sessions corresponding to different users, several SMTP servers and the use of creating MIME messages and use of transport.sendMessage method. I know Javamail is oriented toward desktop-use which makes me suspect it may not have been built with threading in mind, and am wondering if anyone has such experience.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
244 views
Welcome To Ask or Share your Answers For Others

1 Answer

Admittedly the thread safety rules for JavaMail are not well documented, but hopefully they mostly match what you would expect.

Multiple threads can use a Session.

Since a Transport represents a connection to a mail server, and only a single thread can use the connection at a time, a Transport will synchronize access from multiple threads to maintain thread safety, but you'll really only want to use it from a single thread.

Similarly, a Store can be used by multiple threads, but access to the underlying connection will be synchronized and single threaded.

A Message should only be modified by a single thread at a time, but multiple threads should be able to read a message safely (although it's not clear why you would want to do that).

Hope that helps...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...