Empty connection pool after 1 min idle

This commit is contained in:
M66B 2020-12-26 13:09:47 +01:00
parent a526ce1614
commit 2cf4158108
2 changed files with 25 additions and 1 deletions

View File

@ -1395,7 +1395,7 @@ public class IMAPStore extends Store
/**
* Empty the connection pool.
*/
private void emptyConnectionPool(boolean force) {
public void emptyConnectionPool(boolean force) {
synchronized (pool) {
for (int index = pool.authenticatedConnections.size() - 1;

View File

@ -111,6 +111,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
private MutableLiveData<List<TupleAccountState>> liveAccountState = new MutableLiveData<>();
private MediatorState liveAccountNetworkState = new MediatorState();
private static final long PURGE_DELAY = 60 * 1000L; // milliseconds
private static final long QUIT_DELAY = 5 * 1000L; // milliseconds
private static final long STILL_THERE_THRESHOLD = 3 * 60 * 1000L; // milliseconds
static final int DEFAULT_POLL_INTERVAL = 0; // minutes
@ -1363,6 +1364,23 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
forced = true;
Runnable purge = new Runnable() {
@Override
public void run() {
executor.submit(new Runnable() {
@Override
public void run() {
try {
Log.i(account.name + " Empty connection pool");
((IMAPStore) istore).emptyConnectionPool(false);
} catch (Throwable ex) {
Log.e(ex);
}
}
});
}
};
Log.i(account.name + " observing operations");
getMainHandler().post(new Runnable() {
@Override
@ -1392,6 +1410,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
}
handling = all;
if (istore instanceof IMAPStore) {
getMainHandler().removeCallbacks(purge);
if (handling.size() == 0)
getMainHandler().postDelayed(purge, PURGE_DELAY);
}
for (Long fid : added.keySet()) {
EntityFolder found = null;
for (EntityFolder f : mapFolders.keySet())