class SyncAsyncTask extends MessengerAsyncTask<Void, Void, Void> { private static final String TAG_TIME = App.newSubTag(App.TAG_TIME, "Async"); @Nonnull private final List<SyncTask> syncTasks; public SyncAsyncTask(@Nonnull List<SyncTask> syncTasks) { super(true); this.syncTasks = syncTasks; } @Override protected Void doWork(@Nonnull List<Void> voids) { for (Account account : getAccountService().getEnabledAccounts()) { final SyncData syncData = new SyncDataImpl(account.getId()); for (SyncTask syncTask : syncTasks) { final long start = currentTimeMillis(); syncTask.doTask(syncData); final long end = currentTimeMillis(); final long duration = end - start; if (duration > 1000) { Log.e( TAG_TIME, "Work time is too long for account: " + account + " and task: " + syncTask + ". Time: " + duration + "ms"); } } } return null; } @Override protected void onSuccessPostExecute(@Nullable Void result) {} @Override public String toString() { return "SyncAsyncTask{" + "syncTasks=" + syncTasks + '}'; } }