private void executePendingTasks() {
        while (true) {
            Runnable task = this.tasks.poll();
            if (task == null)
                break;

            if (this.listener != null)
                this.listener.executingTask(task);

            try {
                task.run();
            } catch (Throwable cause) {
                if (this.listener != null)
                    this.listener.taskCrashed(task, cause);
                else
                    cause.printStackTrace();
            }
        }
    }