采用apache的commons-email包发送邮件死锁

采用apache的commons-email包发邮件时候,程序卡住停顿了,使用jstack命令查看栈信息如下:


   java.lang.Thread.State: RUNNABLE
    at java.net.SocketInputStream.socketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:129)
    at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
    at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
    at java.io.BufferedInputStream.read(BufferedInputStream.java:237)
    - locked <0x00000007fb055378> (a java.io.BufferedInputStream)
    at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:88)
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:1589)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1369)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:412)
    at javax.mail.Service.connect(Service.java:288)
    - locked <0x00000007fb0515d8> (a com.sun.mail.smtp.SMTPTransport)
    at javax.mail.Service.connect(Service.java:169)
    at javax.mail.Service.connect(Service.java:118)
    at javax.mail.Transport.send0(Transport.java:188)
    at javax.mail.Transport.send(Transport.java:118)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at com.renren.zhaopin.mail.util.MailPostUtil.postMail(MailPostUtil.java:61)
    at com.renren.zhaopin.mail.util.MailPostUtil.postMail(MailPostUtil.java:39)
    at com.renren.xoa2.xiaozhao.mail.service.BaskGroundService$Consumer.waitConsumerEmail(BaskGroundService.java:212)
    at com.renren.xoa2.xiaozhao.mail.service.BaskGroundService$Consumer.run(BaskGroundService.java:152)
    at java.lang.Thread.run(Thread.java:662)

通过查找发现,原来是一台postfix邮件服务器挂了,导致一直占用io,而连接的时候,未设置超时等信息所致。

解决方法:

1)找到挂掉的服务器,去掉即可。

2)完善发送程序,发送代码中加入以下代码:

 email.setSocketTimeout(60*1000);
 email.setSocketConnectionTimeout(60*1000);



你可能感兴趣的:(locked,0x00000007fb0)