2014-09-24 158 views
0

我的應用程序有時在POP3連接中打開文件夾時卡住了。它在2-3周內只發生一次。我們每隔5分鐘檢查一次帳戶,當它發生困難時,不能再次連接,因爲我們鎖定了用戶名,並在連接完成時解鎖。Java郵件被卡在打開的文件夾中。開放Folder.open

這是一個多線程應用程序,其他線程仍然有效。

它連接在一個私人電子郵件服務器。

我VisualVM的聯繫,以獲得在那裏stucked,這裏是線程堆棧跟蹤:

"Monitor-EMAIL-925" - Thread [email protected] 
java.lang.Thread.State: RUNNABLE 
at java.net.SocketInputStream.socketRead0(Native Method) 
at java.net.SocketInputStream.read(Unknown Source) 
at java.net.SocketInputStream.read(Unknown Source) 
at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:124) 
at java.io.BufferedInputStream.fill(Unknown Source) 
at java.io.BufferedInputStream.read(Unknown Source) 
- locked <265d84f2> (a java.io.BufferedInputStream) 
at java.io.DataInputStream.readLine(Unknown Source) 
at com.sun.mail.pop3.Protocol.readResponse(Protocol.java:714) 
at com.sun.mail.pop3.Protocol.simpleCommand(Protocol.java:689) 
at com.sun.mail.pop3.Protocol.<init>(Protocol.java:114) 
at com.sun.mail.pop3.POP3Store.getPort(POP3Store.java:260) 
- locked <1580e275> (a com.sun.mail.pop3.POP3Store) 
at com.sun.mail.pop3.POP3Folder.open(POP3Folder.java:208) 
- locked <1245cbd5> (a com.sun.mail.pop3.POP3Folder) 
at com.xxx.mail.MonitorEmail.processarPasta(MonitorEmail.java:377) 
at com.xxx.mail.MonitorEmail.run(MonitorEmail.java:341) 
at java.lang.Thread.run(Unknown Source) 

Locked ownable synchronizers: 
- None 

我使用JavaMail-1.4.7版本。

方法com.sun.mail.pop3.Protocol.readResponse(Protocol.java:714)具有DataInputStream類的棄用值的呼叫:

/** 
* Read the response to a command. 
*/ 
private Response readResponse() throws IOException { 
    String line = null; 
    try { 
     line = input.readLine(); // XXX - readLine is deprecated 
    } catch (InterruptedIOException iioex) { 
     /* 
     * If we get a timeout while using the socket, we have no idea what 
     * state the connection is in. The server could still be alive, but 
     * slow, and could still be sending data. The only safe way to 
     * recover is to drop the connection. 
     */ 
     try { 
      socket.close(); 
     } catch (IOException cex) { 
     } 
     throw new EOFException(iioex.getMessage()); 
    } catch (SocketException ex) { 
     /* 
     * If we get an error while using the socket, we have no idea what 
     * state the connection is in. The server could still be alive, but 
     * slow, and could still be sending data. The only safe way to 
     * recover is to drop the connection. 
     */ 
     try { 
      socket.close(); 
     } catch (IOException cex) { 
     } 
     throw new EOFException(ex.getMessage()); 
    } 

    if (line == null) { 
     traceLogger.finest("<EOF>"); 
     throw new EOFException("EOF on socket"); 
    } 
    Response r = new Response(); 
    if (line.startsWith("+OK")) 
     r.ok = true; 
    else if (line.startsWith("-ERR")) 
     r.ok = false; 
    else 
     throw new IOException("Unexpected response: " + line); 
    int i; 
    if ((i = line.indexOf(' ')) >= 0) 
     r.data = line.substring(i + 1); 
    return r; 
} 

針對javamail的-1.5.2本方法的比較是不同的,只是返回一個響應:

public Response readResponse() 
    throws IOException, ProtocolException { 
    return new Response(this); 
} 

有沒有人有過這個問題?

回答

1

可能是某種網絡或服務器故障。您可能需要配置超時,以便您的應用程序可以從這樣的問題中恢復。

+0

我要設置這兩個「屬性mail.pop3.timeout」和「mail.pop3.connectiontimeout」。如果打開文件夾時連接超時,我會接受您的答案。 – leonardoborges 2014-10-02 14:55:27

+0

超時解決我的問題。謝謝! – leonardoborges 2014-10-09 19:10:13