Task monitoring simplification

pull/199/head
M66B 3 years ago
parent 408809076c
commit 8fecd5bc48

@ -53,7 +53,6 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
private boolean count = true; private boolean count = true;
private String name; private String name;
private long created;
private long started; private long started;
private boolean reported; private boolean reported;
private boolean interrupted; private boolean interrupted;
@ -70,10 +69,6 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT"; static final String ACTION_TASK_COUNT = BuildConfig.APPLICATION_ID + ".ACTION_TASK_COUNT";
public SimpleTask() {
created = new Date().getTime();
}
public SimpleTask<T> setLog(boolean log) { public SimpleTask<T> setLog(boolean log) {
this.log = log; this.log = log;
if (!log) if (!log)
@ -280,17 +275,15 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
long now = new Date().getTime(); long now = new Date().getTime();
synchronized (tasks) { synchronized (tasks) {
for (SimpleTask task : tasks) { for (SimpleTask task : tasks) {
long pending = now - task.created;
long elapsed = now - task.started; long elapsed = now - task.started;
if (elapsed > CANCEL_AFTER && !task.interrupted && task.started > 0) { if (elapsed > CANCEL_AFTER && !task.interrupted && task.started > 0) {
task.interrupted = true; task.interrupted = true;
if (task.future != null && !task.future.isDone()) if (task.future != null && !task.future.isDone())
task.future.cancel(true); task.future.cancel(true);
} else if (pending > REPORT_AFTER && !task.reported) { } else if (elapsed > REPORT_AFTER && !task.reported) {
task.reported = true; task.reported = true;
Log.e("Long running task " + task.name + Log.e("Long running task " + task.name +
" pending=" + (pending / 1000) + " elapsed=" + (task.started == 0 ? null : elapsed / 1000) +
" elapsed=" + (elapsed / 1000) +
" done=" + (task.future == null ? null : task.future.isDone()) + " done=" + (task.future == null ? null : task.future.isDone()) +
" cancelled=" + (task.future == null ? null : task.future.isCancelled())); " cancelled=" + (task.future == null ? null : task.future.isCancelled()));
} }
@ -319,11 +312,8 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
@Override @Override
public String toString() { public String toString() {
long now = new Date().getTime(); long now = new Date().getTime();
long pending = now - created; return name + " elapsed=" +
long elapsed = now - started; (started == 0 ? null : (now - started) / 1000) + "s";
return name +
" pending=" + (pending / 1000) + "s" +
" elapsed=" + (elapsed / 1000) + "s";
} }
static int getCount() { static int getCount() {

Loading…
Cancel
Save