private void doNext(Calendar calendar, int dot) {
        List<Integer> resets = new ArrayList();
        int second = calendar.get(13);
        List<Integer> emptyList = Collections.emptyList();
        int updateSecond = this.findNext(this.seconds, second, calendar, 13, 12, emptyList);
        if (second == updateSecond) {
            resets.add(13);
        }

        int minute = calendar.get(12);
        int updateMinute = this.findNext(this.minutes, minute, calendar, 12, 11, resets);
        if (minute == updateMinute) {
            resets.add(12);
        } else {
            this.doNext(calendar, dot);
            return; //----------------------------------------可以直接返回 在后面走可能就是多余的
        }

        int hour = calendar.get(11);
        int updateHour = this.findNext(this.hours, hour, calendar, 11, 7, resets);
        if (hour == updateHour) {
            resets.add(11);
        } else {
            this.doNext(calendar, dot);
            return; //----------------------------------------可以直接返回 在后面走可能就是多余的
        }

        int dayOfWeek = calendar.get(7);
        int dayOfMonth = calendar.get(5);
        int updateDayOfMonth = this.findNextDay(calendar, this.daysOfMonth, dayOfMonth, this.daysOfWeek, dayOfWeek, resets);
        if (dayOfMonth == updateDayOfMonth) {
            resets.add(5);
        } else {
            this.doNext(calendar, dot);
            return; //----------------------------------------可以直接返回 在后面走可能就是多余的
        }

        int month = calendar.get(2);
        int updateMonth = this.findNext(this.months, month, calendar, 2, 1, resets);
        if (month != updateMonth) {
            if (calendar.get(1) - dot > 4) {
                throw new IllegalArgumentException("Invalid cron expression \"" + this.expression + "\" led to runaway search for next trigger");
            }

            this.doNext(calendar, dot);
        }
    }

如果doNext在递归时 内层的doNext会检测新值和旧值是否相等并重置时间 等内层的doNext 执行完成后 外层的doNext 在判断是一定是相等的

Comment From: poutsma

Hi, none of us are able to speak Chinese.

Would you (or anybody else) be able to provide an English translation? If not, a PR would be good enough as well, if the changes are clear enough.

Comment From: 17683908932

sorry,

this doNext method ..

private void doNext(Calendar calendar, int dot) {
        List<Integer> resets = new ArrayList();
        int second = calendar.get(13);
        List<Integer> emptyList = Collections.emptyList();
        int updateSecond = this.findNext(this.seconds, second, calendar, 13, 12, emptyList);
        if (second == updateSecond) {
            resets.add(13);
        }

        int minute = calendar.get(12);
        int updateMinute = this.findNext(this.minutes, minute, calendar, 12, 11, resets);
        if (minute == updateMinute) {
            resets.add(12);
        } else {
            this.doNext(calendar, dot);
            return; //----------------------------------------can return. It's redundant in the future
        }

        int hour = calendar.get(11);
        int updateHour = this.findNext(this.hours, hour, calendar, 11, 7, resets);
        if (hour == updateHour) {
            resets.add(11);
        } else {
            this.doNext(calendar, dot);
            return; //----------------------------------------can return. It's redundant in the future
        }

        int dayOfWeek = calendar.get(7);
        int dayOfMonth = calendar.get(5);
        int updateDayOfMonth = this.findNextDay(calendar, this.daysOfMonth, dayOfMonth, this.daysOfWeek, dayOfWeek, resets);
        if (dayOfMonth == updateDayOfMonth) {
            resets.add(5);
        } else {
            this.doNext(calendar, dot);
            return; //---------------------------------------- can return. It's redundant in the future
        }

        int month = calendar.get(2);
        int updateMonth = this.findNext(this.months, month, calendar, 2, 1, resets);
        if (month != updateMonth) {
            if (calendar.get(1) - dot > 4) {
                throw new IllegalArgumentException("Invalid cron expression \"" + this.expression + "\" led to runaway search for next trigger");
            }

            this.doNext(calendar, dot);
        }
    }

the doNext method when recursion doNext method in the inner layer will detect whether the new value and the old value are equal and reset the time. After the inner layer doNext method is executed, the new value and the old value must be the same. No need to judge in the outer layer

Comment From: poutsma

Just out of curiosity: did you use some sort of runtime analysis tool to come to this optimisation? The code snippets you provide use the literal values instead of the constants (i.e. calendar.get(13) instead of calendar.get(Calendar.SECOND).)

Comment From: poutsma

Thank you for the report. We have decided to deprecate CronExpression in Spring 5.3, and replace it with a new CronExpression API. The main reason was maintainability: none of us felt comfortable changing CronSequenceGenerator, due to its complex nature. As a result, we won't be making the changes to CronSequenceGenerator as you suggested.