@@ -0,0 +1,2909 @@
+package com.alibaba.demo.ttl;%0A%0Aimport com.alibaba.ttl.TtlRunnable;%0Aimport com.alibaba.ttl.threadpool.TtlExecutors;%0A%0Aimport java.util.concurrent.ArrayBlockingQueue;%0Aimport java.util.concurrent.ExecutorService;%0Aimport java.util.concurrent.ThreadPoolExecutor;%0Aimport java.util.concurrent.TimeUnit;%0A%0A/**%0A * Simple demo code for issue%0A * https://github.com/alibaba/transmittable-thread-local/issues/340%0A */%0Apublic class CustomizedBlockingQueueWithTtlDemo %7B%0A    public static void main(String%5B%5D args) throws Exception %7B%0A        final MyBlockingQueue myBlockingQueue = new MyBlockingQueue();%0A%0A        final ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(%0A                1, 1, 1L, TimeUnit.SECONDS, myBlockingQueue);%0A        final ExecutorService ttlExecutorService = TtlExecutors.getTtlExecutorService(threadPoolExecutor);%0A%0A        ttlExecutorService.execute(new MyTask(%22accept-1%22));%0A        ttlExecutorService.execute(new MyTask(%22DISCARDED%22));%0A        ttlExecutorService.execute(new MyTask(%22accept-2%22));%0A%0A        ttlExecutorService.shutdown();%0A        if (!ttlExecutorService.awaitTermination(10, TimeUnit.SECONDS)) %7B%0A            throw new IllegalStateException(%22Fail to shutdown executor service%22);%0A        %7D%0A    %7D%0A%0A    private static class MyTask implements Runnable %7B%0A        private final String msg;%0A%0A        private MyTask(String msg) %7B%0A            this.msg = msg;%0A        %7D%0A%0A        @Override%0A        public void run() %7B%0A            System.out.println(%22MyTask: %22 + msg);%0A        %7D%0A    %7D%0A%0A    private static class MyBlockingQueue extends ArrayBlockingQueue%3CRunnable%3E %7B%0A        public MyBlockingQueue() %7B%0A            super(16);%0A        %7D%0A%0A        @Override%0A        public boolean offer(final Runnable runnable) %7B%0A            // unwrap TtlRunnable first%0A            final Runnable unwrap  = TtlRunnable.unwrap(runnable);%0A%0A            final MyTask myTask = (MyTask) unwrap;%0A            if (myTask.msg.startsWith(%22accept-%22)) %7B%0A                // ignore result/return value of offer, BAD!!%0A                //   does not follow the contract of method offer%0A                // this is just a simple demo!%0A                super.offer(runnable);%0A            %7D%0A%0A            // always return true even if discard the task, BAD!!%0A            //   does not follow the contract of method offer%0A            // this is just a simple demo!%0A            return true;%0A        %7D%0A%0A        @Override%0A        public void put(final Runnable runnable) throws InterruptedException %7B%0A            // unwrap TtlRunnable first%0A            final Runnable unwrap  = TtlRunnable.unwrap(runnable);%0A%0A            final MyTask myTask = (MyTask) unwrap;%0A            // discard task if not satisfied, BAD!!%0A            //   does not follow the contract of method put%0A            // this is just a simple demo!%0A            if (myTask.msg.startsWith(%22accept-%22)) %7B%0A                super.put(runnable);%0A            %7D%0A        %7D%0A    %7D%0A%7D%0A%0A

add demo code `CustomizedBlockingQueueWithTtlDemo` for #340