@Override
    public void clear() {
        List<Closure> savedQueue;
        this.lock.lock();
        try {
            this.firstIndex = 0;
            savedQueue = this.queue;
            this.queue = new LinkedList<>();
        } finally {
            this.lock.unlock();
        }

        final Status status = new Status(RaftError.EPERM, "Leader stepped down");
        ThreadPoolsFactory.runInThread(this.groupId, () -> {
            for (final Closure done : savedQueue) {
                if (done != null) {
                    done.run(status);
                }
            }
        });
    }
Closure queue implementation.

@author boyan (boyan@alibaba-inc.com)

2018-Mar-28 11:44:01 AM
jraft-core/src/main/java/com/alipay/sofa/jraft/closure/ClosureQueueImpl.java