void (@NotNull Runnable firstTask, long status) { try { Runnable command = new ContextAwareRunnable() { final AtomicReference<Runnable> currentTask = new AtomicReference<>(firstTask); @Override public void run() { try (AccessToken ignored = ThreadContext.resetThreadContext()) { // This runnable is intended to be used for offloading the queue by executing stored tasks. // It means that it shall not possess a thread context, // but the executed tasks must have a context. if (myChangeThreadName) { ConcurrencyUtil.runUnderThreadName(myName, this::executeFirstTaskAndHelpQueue); } else { executeFirstTaskAndHelpQueue(); } } } private void executeFirstTaskAndHelpQueue() { Runnable task = currentTask.get(); do { currentTask.set(task); doRun(task); task = pollOrGiveUp(status); } while (task != null); } @Override public String toString() { return String.valueOf(info(currentTask.get())); } }; myBackendExecutor.execute(command); } catch (Error | RuntimeException e) { myStatus.decrementAndGet(); throw e; } }