Count running tasks only

This commit is contained in:
M66B 2021-06-18 13:10:16 +02:00
parent a0f41d59a4
commit 0a8d831bdc
1 changed files with 7 additions and 3 deletions

View File

@ -315,15 +315,19 @@ 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();
return name + " elapsed=" + long elapsed = now - started;
(started == 0 ? null : (now - started) / 1000) + "s"; return name +
" elapsed=" + (started == 0 ? null : elapsed / 1000) +
" done=" + (future == null ? null : future.isDone()) +
" cancelled=" + (future == null ? null : future.isCancelled());
} }
static int getCount() { static int getCount() {
int executing = 0; int executing = 0;
synchronized (tasks) { synchronized (tasks) {
for (SimpleTask task : tasks) for (SimpleTask task : tasks)
if (task.started > 0 && task.count) if (task.count &&
task.future != null && !task.future.isDone())
executing++; executing++;
} }
return executing; return executing;