mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-25 15:32:52 +00:00
Empty connection pool after 1 min idle
This commit is contained in:
parent
a526ce1614
commit
2cf4158108
2 changed files with 25 additions and 1 deletions
|
@ -1395,7 +1395,7 @@ public class IMAPStore extends Store
|
||||||
/**
|
/**
|
||||||
* Empty the connection pool.
|
* Empty the connection pool.
|
||||||
*/
|
*/
|
||||||
private void emptyConnectionPool(boolean force) {
|
public void emptyConnectionPool(boolean force) {
|
||||||
|
|
||||||
synchronized (pool) {
|
synchronized (pool) {
|
||||||
for (int index = pool.authenticatedConnections.size() - 1;
|
for (int index = pool.authenticatedConnections.size() - 1;
|
||||||
|
|
|
@ -111,6 +111,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
private MutableLiveData<List<TupleAccountState>> liveAccountState = new MutableLiveData<>();
|
private MutableLiveData<List<TupleAccountState>> liveAccountState = new MutableLiveData<>();
|
||||||
private MediatorState liveAccountNetworkState = new MediatorState();
|
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 QUIT_DELAY = 5 * 1000L; // milliseconds
|
||||||
private static final long STILL_THERE_THRESHOLD = 3 * 60 * 1000L; // milliseconds
|
private static final long STILL_THERE_THRESHOLD = 3 * 60 * 1000L; // milliseconds
|
||||||
static final int DEFAULT_POLL_INTERVAL = 0; // minutes
|
static final int DEFAULT_POLL_INTERVAL = 0; // minutes
|
||||||
|
@ -1363,6 +1364,23 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
|
|
||||||
forced = true;
|
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");
|
Log.i(account.name + " observing operations");
|
||||||
getMainHandler().post(new Runnable() {
|
getMainHandler().post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -1392,6 +1410,12 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||||
}
|
}
|
||||||
handling = all;
|
handling = all;
|
||||||
|
|
||||||
|
if (istore instanceof IMAPStore) {
|
||||||
|
getMainHandler().removeCallbacks(purge);
|
||||||
|
if (handling.size() == 0)
|
||||||
|
getMainHandler().postDelayed(purge, PURGE_DELAY);
|
||||||
|
}
|
||||||
|
|
||||||
for (Long fid : added.keySet()) {
|
for (Long fid : added.keySet()) {
|
||||||
EntityFolder found = null;
|
EntityFolder found = null;
|
||||||
for (EntityFolder f : mapFolders.keySet())
|
for (EntityFolder f : mapFolders.keySet())
|
||||||
|
|
Loading…
Reference in a new issue