java mail Store.connect hangs - 不会超时

时间:2011-12-30 00:36:18

标签: java imap javamail

我使用普通的旧邮件(mail-1.4.1.jar - JVM 1.6.0_03-b05)连接到IMAP商店:

Session mailSession = Session.getInstance(new Properties(), null);
Store store = mailSession.getStore("imap");
store.connect(host, user, pwd); // Hangs here
folder = store.getFolder("INBOX");
folder.open(Folder.READ_WRITE);
...

问题是,线程偶尔交给store.connect并且永远不会返回。

"MyThread" daemon prio=10 tid=0x0a9c3000 nid=0x2095 runnable [0x9ccd3000..0x9ccd4130]
   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 <0xc09003e8> (a java.io.BufferedInputStream)
        at com.sun.mail.iap.ResponseInputStream.readResponse(ResponseInputStream.java:97)
        at com.sun.mail.iap.Response.<init>(Response.java:96)
        at com.sun.mail.imap.protocol.IMAPResponse.<init>(IMAPResponse.java:61)
        at com.sun.mail.imap.protocol.IMAPResponse.readResponse(IMAPResponse.java:135)
        at com.sun.mail.imap.protocol.IMAPProtocol.readResponse(IMAPProtocol.java:261)
        at com.sun.mail.iap.Protocol.<init>(Protocol.java:114)
        at com.sun.mail.imap.protocol.IMAPProtocol.<init>(IMAPProtocol.java:104)
        at com.sun.mail.imap.IMAPStore.protocolConnect(IMAPStore.java:538)
        - locked <0xc04c73d0> (a com.sun.mail.imap.IMAPStore)
        at javax.mail.Service.connect(Service.java:288)
        - locked <0xc04c73d0> (a com.sun.mail.imap.IMAPStore)
        at javax.mail.Service.connect(Service.java:169)
        at package.MyClass.checkInbox(MyClass.java:116)

javamail spec中没有提及超时设置,我在SessionStore上找不到任何合适的'setter'方法。

欢迎任何建议。

1 个答案:

答案 0 :(得分:1)

请参阅com.sun.mail.imap package的javadocs,了解可以设置控制的属性(以及其他内容)超时。哦,您可能想要升级到最新版本的JavaMail。