背景
最近发现项目中有关发送邮件的模块偶尔会阻塞住,导致整个线程阻塞。诡异的是没有捕获到任何异常日志,程序莫名其妙就卡在了 sendMail 上。
后来想到发送邮件的内容过大,可能由于这个原因导致,所以找了一下有关 JavaMail 超时设置的资料。现做整理,顺便聊聊一些小坑。
JavaMail smtp 超时参数参数
类型
描述
mail.smtp.connectiontimeout
int
Socket connection timeout value in milliseconds. This timeout is implemented by java.net.Socket. Default is infinite timeout.
mail.smtp.timeout
int
Socket read timeout value in milliseconds. This timeout is implemented by java.net.Socket. Default is infinite timeout.
mail.smtp.writetimeout
int
Socket write timeout value in milliseconds. This timeout is implemented by using a java.util.concurrent.ScheduledExecutorService per connection that schedules a thread to close the socket if the timeout expires. Thus, the overhead of using this timeout is one thread per connection. Default is infinite timeout