From 0f01041b87a06af6ccd36f0989fdecb784eb3c1c Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 18 Apr 2022 09:36:59 +0200 Subject: [PATCH] Cancel empty pool on close --- .../eu/faircode/email/ServiceSynchronize.java | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java index 6ccffddaa2..8bc2b88133 100644 --- a/app/src/main/java/eu/faircode/email/ServiceSynchronize.java +++ b/app/src/main/java/eu/faircode/email/ServiceSynchronize.java @@ -1459,6 +1459,28 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences } }); + final Runnable purge = new RunnableEx("purge") { + @Override + public void delegate() { + executor.submit(new RunnableEx("purge#exec") { + @Override + public void delegate() { + try { + wlAccount.acquire(); + + // Close cached connections + Log.i(account.name + " Empty connection pool"); + ((IMAPStore) iservice.getStore()).emptyConnectionPool(false); + } catch (Throwable ex) { + Log.e(ex); + } finally { + wlAccount.release(); + } + } + }); + } + }; + final Map mapFolders = new LinkedHashMap<>(); List idlers = new ArrayList<>(); try { @@ -1834,28 +1856,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences forced = true; - final Runnable purge = new RunnableEx("purge") { - @Override - public void delegate() { - executor.submit(new RunnableEx("purge#exec") { - @Override - public void delegate() { - try { - wlAccount.acquire(); - - // Close cached connections - Log.i(account.name + " Empty connection pool"); - ((IMAPStore) istore).emptyConnectionPool(false); - } catch (Throwable ex) { - Log.e(ex); - } finally { - wlAccount.release(); - } - } - }); - } - }; - final long serial = state.getSerial(); Log.i(account.name + " observing operations"); @@ -2314,6 +2314,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences EntityLog.log(this, EntityLog.Type.Account, account, account.name + " closing"); + getMainHandler().removeCallbacks(purge); + // Stop watching operations Log.i(account.name + " stop watching operations"); final TwoStateOwner _owner = cowner.value;