1
我使用的是普通的舊Java郵件(郵件1.4.1.jar - JVM 1.6.0_03-B05)連接到IMAP存儲區:Java郵件Store.connect掛起 - 不超時
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沒有超時設置一提,我找不到在任Session
或Store
任何合適的「二傳手」的方法。
歡迎任何建議。
你設置了什麼超時參數來解決你的問題? – pgratton 2013-01-21 15:39:16