public void register(GracefulShutdownHook shutdownHook) {
        if (isShuttingDown.get()) {
            // Avoid any changes to the shutdown hooks set when the shutdown is already in progress
            throw new IllegalStateException("Couldn't register shutdown hook because shutdown is already in progress");
        }
        shutdownHooks.add(requireNonNull(shutdownHook, "shutdownHook cannot be null"));
    }
@DisabledIfEnvironmentVariable(named = "CI", matches = "true", disabledReason = "Flaky on Jenkins")
    @Test
    @Timeout(1)
    public void registerMany() throws Exception {

        final int numberOfHooks = 20;
        final AtomicInteger hooksStarted = new AtomicInteger(0);
        final AtomicInteger hooksFinished = new AtomicInteger(0);
        final AtomicInteger maxConcurrency = new AtomicInteger(0);

        final CountDownLatch countDownLatch = new CountDownLatch(1);

        for (int i = 0; i < numberOfHooks; i++) {
            shutdownService.register(() -> {
                hooksStarted.incrementAndGet();
                countDownLatch.await();
                maxConcurrency.getAndAccumulate(hooksStarted.get() - hooksFinished.get(), Math::max);
                hooksFinished.incrementAndGet();
            });
        }

        shutdownService.stopAsync();

        // Wait until 10 hooks are being actively executed.
        // This should not lead to other hooks being skipped, which was a bug.
        Awaitility.await()
                .pollInterval(10, TimeUnit.MILLISECONDS)
                .atMost(100, TimeUnit.MILLISECONDS)
                .until(() -> hooksStarted.get() >= 10);

        countDownLatch.countDown();

        shutdownService.awaitTerminated(200, TimeUnit.MILLISECONDS);

        assertThat(hooksStarted.get()).isEqualTo(numberOfHooks);
        assertThat(hooksFinished.get()).isEqualTo(numberOfHooks);
        assertThat(maxConcurrency.get()).isEqualTo(10);
    }