Make sure ImapFolderPusher is not started or stopped twice

This commit is contained in:
cketti 2016-02-12 06:27:14 +01:00
parent 01a14b9f1f
commit b34f3ad669

View file

@ -57,6 +57,10 @@ class ImapFolderPusher extends ImapFolder {
public void start() {
synchronized (threadLock) {
if (listeningThread != null) {
throw new IllegalStateException("start() called twice");
}
listeningThread = new Thread(new PushRunnable());
listeningThread.start();
}
@ -70,9 +74,16 @@ class ImapFolderPusher extends ImapFolder {
}
public void stop() {
stop = true;
synchronized (threadLock) {
if (listeningThread == null) {
throw new IllegalStateException("stop() called twice");
}
interruptListeningThread();
stop = true;
listeningThread.interrupt();
listeningThread = null;
}
ImapConnection conn = connection;
if (conn != null) {
@ -86,14 +97,6 @@ class ImapFolderPusher extends ImapFolder {
}
}
private void interruptListeningThread() {
synchronized (threadLock) {
if (listeningThread != null) {
listeningThread.interrupt();
}
}
}
@Override
protected void handleUntaggedResponse(ImapResponse response) {
if (response.getTag() == null && response.size() > 1) {