void () { myFlushing = true; try { List<Update> all; synchronized (myScheduledUpdates) { all = getAllScheduledUpdates(); myScheduledUpdates.clear(); } for (Update each : all) { each.setProcessed(); } Update[] array = all.toArray(new Update[0]); Arrays.sort(array, Comparator.comparingInt(Update::getPriority)); execute(array); } finally { myFlushing = false; if (isEmpty()) { finishActivity(); } } }