Code example for Queue

Methods: offer, poll

0
    SerialExecutor(Executor executor) {
        this.executor = executor;
    } 
 
    public synchronized void execute(final Runnable r) {
        tasks.offer(new Runnable() {
            public void run() { 
                try { 
                    r.run();
                } finally { 
                    scheduleNext(); 
                } 
            } 
        }); 
        if (active == null) {
            scheduleNext(); 
        } 
    } 
 
    protected synchronized void scheduleNext() { 
        if ((active = tasks.poll()) != null) {
            executor.execute(active);
        } 
    } 
}