Duty/cycle end

pull/194/merge
M66B 4 years ago
parent 3c3403cb0e
commit a887657618

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

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

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

Loading…
Cancel
Save