|
|
|
@ -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) {
|
|
|
|
|