@Override
    public void destroy() {
        // instance has been destroyed, not need to call this method again
        if (!isActive()) {
            log.warn("Failed to destroy ExecutorService '{}' because it has already been destroyed", getThreadPoolId());
            return;
        }
        if (isWaitForTasksToCompleteOnShutdown()) {
            super.shutdown();
        } else {
            super.shutdownNow();
        }
        getThreadPoolPluginManager().clear();
        log.info("ExecutorService '{}' has been destroyed", getThreadPoolId());

        // modify the flag to false avoid the method being called repeatedly
        active.set(false);
    }
@Test
    public void testDestroyWhenNotWaitForTask() {
        DynamicThreadPoolExecutor executor = new DynamicThreadPoolExecutor(
                1, 1, 1000L, TimeUnit.MILLISECONDS,
                1000L, false, 1000L,
                new ArrayBlockingQueue<>(1), "test", Thread::new, new ThreadPoolExecutor.DiscardOldestPolicy());
        AtomicInteger count = new AtomicInteger(0);

        executor.execute(() -> {
            ThreadUtil.sleep(500L);
            count.incrementAndGet();
        });
        executor.execute(() -> {
            ThreadUtil.sleep(500L);
            count.incrementAndGet();
        });
        executor.destroy();

        // waiting for terminated
        while (!executor.isTerminated()) {
        }
        Assert.assertEquals(1, count.get());
    }