@Override
    public void close() {
        isOpen.set(false);
        Iterator<Future<?>> iterator = futures.iterator();
        while (iterator.hasNext()) {
            Future<?> future = iterator.next();
            iterator.remove();
            if (!future.isDone() && !future.isCancelled() && !future.cancel(true)) {
                log.warn("Could not cancel " + future);
            }
        }
        if (shutdownOnClose) {
            executorService.shutdownNow();
        }
    }
@Test
    public void testBasicRunnable() throws InterruptedException {
        try {
            CloseableExecutorService service = new CloseableExecutorService(executorService);
            CountDownLatch startLatch = new CountDownLatch(QTY);
            CountDownLatch latch = new CountDownLatch(QTY);
            for (int i = 0; i < QTY; ++i) {
                submitRunnable(service, startLatch, latch);
            }

            assertTrue(startLatch.await(3, TimeUnit.SECONDS));
            service.close();
            assertTrue(latch.await(3, TimeUnit.SECONDS));
        } catch (AssertionError e) {
            throw e;
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }