Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Transport.send() is it thread-safe?

The method is static, but I cannot find mention of if it is thread-safe or not. I plan on hitting this method with several threads at once and I would like to avoid a synchronized block if possible.

javax.mail.Transport.send(msg);
like image 528
Adam Avatar asked Nov 21 '08 15:11

Adam


1 Answers

It is usually bad design and a violation of expectations to have a static method that is not thread-safe.

The documentation indeed appears to be devoid of any mention of thread-safety, but a quick glance through the code suggests that the implementation is thread-safe by creating a thread-confined Transport instance on every call and delegating to that.

To be absolutely sure I recommend pulling a couple of days out the calendar for a proper analysis.

like image 169
Chris Vest Avatar answered Sep 30 '22 23:09

Chris Vest