Don't hold 'connections' monitor while checking retrieved connection

This commit is contained in:
cketti 2016-02-17 20:04:08 +01:00
parent b34f3ad669
commit 200ee27980

View file

@ -308,22 +308,26 @@ public class ImapStore extends RemoteStore {
}
ImapConnection getConnection() throws MessagingException {
ImapConnection connection;
while ((connection = pollConnection()) != null) {
try {
connection.executeSimpleCommand(Commands.NOOP);
break;
} catch (IOException ioe) {
connection.close();
}
}
if (connection == null) {
connection = createImapConnection();
}
return connection;
}
private ImapConnection pollConnection() {
synchronized (connections) {
ImapConnection connection;
while ((connection = connections.poll()) != null) {
try {
connection.executeSimpleCommand(Commands.NOOP);
break;
} catch (IOException ioe) {
connection.close();
}
}
if (connection == null) {
connection = createImapConnection();
}
return connection;
return connections.poll();
}
}