class TaskRouter {

    public synchronized ExecutorTask pickExecutorTask(Lock lock) {
        MultiSkipList<ExecutorTask> idleTasks = TaskRouter.getInstance().getIdleTasks();
        ExecutorTask taskPicked = null;
        lock.lock();
        try {
            // 对 virtual seg 锁建索引
            taskConflict.initVirtualLocks(ConsumeQueue.getInstance().getTaskList());
            Iterator<ExecutorTask> iterator = idleTasks.iterator();
            while (iterator.hasNext()) {
                ExecutorTask curTask = iterator.next();
                if (isQualified(curTask)) {
                    taskPicked = curTask;
                    break;
                }
            }
        } finally {
            lock.unlock();
        }
        // 完成冲突判定，删除 virtual seg 锁索引
        taskConflict.finishVirtualLocks();
        if (taskPicked != null && TaskRouter.getInstance().remove(taskPicked)) {
            return taskPicked;
        } else {
            return null;
        }
    }

    private  TaskRouter();

}