Duty/cycle end

This commit is contained in:
M66B 2022-02-05 21:21:33 +01:00
parent 3c3403cb0e
commit a887657618
3 changed files with 20 additions and 6 deletions

View File

@ -3559,7 +3559,7 @@ class Core {
} finally {
// Free memory
isub[j] = null;
dc.stop(state.getForeground());
dc.stop(state.getForeground(), from == 0 && j == 0);
}
}
}
@ -3647,7 +3647,7 @@ class Core {
} finally {
// Free memory
isub[j] = null;
dc.stop(state.getForeground());
dc.stop(state.getForeground(), from == 0 && j == 0);
}
}
}

View File

@ -20,6 +20,8 @@ package eu.faircode.email;
*/
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
public class DutyCycle {
private final String name;
@ -48,7 +50,19 @@ public class DutyCycle {
start = new Date().getTime();
}
public void stop(boolean foreground) {
public void stop(boolean foreground, ExecutorService executor) {
boolean done = false;
try {
done = (executor instanceof ThreadPoolExecutor &&
((ThreadPoolExecutor) executor).getQueue().size() == 0);
} catch (Throwable ex) {
Log.e(ex);
} finally {
stop(foreground, done);
}
}
public void stop(boolean foreground, boolean done) {
long end = new Date().getTime();
if (last != null)
@ -60,8 +74,8 @@ public class DutyCycle {
if (busy + idle > interval) {
long wait = (duration - idle);
Log.i(name + " busy=" + busy + " idle=" + idle +
" wait=" + wait + " foreground=" + foreground);
if (wait > 0 && foreground) {
" wait=" + wait + " foreground=" + foreground + " done=" + done);
if (wait > 0 && foreground && !done) {
try {
Thread.sleep(wait);
} catch (InterruptedException ex) {

View File

@ -1994,7 +1994,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
iservice, ifolder,
state, serial);
} finally {
dc.stop(state.getForeground());
dc.stop(state.getForeground(), executor);
}
} catch (Throwable ex) {