@Override
    public void run() {
        if (isAlreadyRunning.compareAndSet(false, true)) {
            if (throwable != null) {
                // Capturing & throwing the exception to propagate the failure to the scheduler (suppress future executions)
                // instead of hiding in the delegated executor.
                rethrow(throwable);
                return;
            }

            executor.execute(runnable);
        }
    }
@Test
    public void givenTheTaskIsAlreadyRunning_whenThreadAttemptToExecuteIt_theExutionWillBeSkipped() throws InterruptedException {
        final ResumableCountingRunnable task = new ResumableCountingRunnable();

        final AtomicInteger counter = new AtomicInteger();
        SynchronousQueue<Runnable> queue = new SynchronousQueue<>() {
            @Override
            public boolean offer(Runnable runnable) {
                counter.incrementAndGet();
                return super.offer(runnable);
            }
        };

        ThreadPoolExecutor executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE,
                60L, TimeUnit.SECONDS, queue);

        //start first task
        DelegateAndSkipOnConcurrentExecutionDecorator decoratedTask =
                decorateAndInvokeRunOnDifferentThread(task, executor);

        //wait until the task is running
        task.awaitExecutionStarted();

        //attempt to start execution from the test thread. this execution should be skipped -> it won't block
        decoratedTask.run();

        //resume the original task
        task.resumeExecution();

        assertEquals(1, task.getExecutionCount());
        assertEquals(1, counter.get());
    }