Don't hold 'connections' monitor while checking retrieved connection
This commit is contained in:
parent
b34f3ad669
commit
200ee27980
1 changed files with 19 additions and 15 deletions
|
@ -308,22 +308,26 @@ public class ImapStore extends RemoteStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
ImapConnection getConnection() throws MessagingException {
|
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) {
|
synchronized (connections) {
|
||||||
ImapConnection connection;
|
return connections.poll();
|
||||||
while ((connection = connections.poll()) != null) {
|
|
||||||
try {
|
|
||||||
connection.executeSimpleCommand(Commands.NOOP);
|
|
||||||
break;
|
|
||||||
} catch (IOException ioe) {
|
|
||||||
connection.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection == null) {
|
|
||||||
connection = createImapConnection();
|
|
||||||
}
|
|
||||||
|
|
||||||
return connection;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue