This commit is contained in:
Looly
2022-04-30 20:47:32 +08:00
parent dea8344d91
commit ca094ca4a8
1356 changed files with 15747 additions and 16033 deletions

View File

@@ -28,7 +28,7 @@ public class CronConfig {
* @param timezone 时区
* @return this
*/
public CronConfig setTimeZone(TimeZone timezone) {
public CronConfig setTimeZone(final TimeZone timezone) {
this.timezone = timezone;
return this;
}
@@ -57,7 +57,7 @@ public class CronConfig {
* @param isMatchSecond {@code true}支持,{@code false}不支持
* @return this
*/
public CronConfig setMatchSecond(boolean isMatchSecond) {
public CronConfig setMatchSecond(final boolean isMatchSecond) {
this.matchSecond = isMatchSecond;
return this;
}

View File

@@ -10,23 +10,23 @@ import cn.hutool.core.text.StrUtil;
public class CronException extends RuntimeException {
private static final long serialVersionUID = 1L;
public CronException(Throwable e) {
public CronException(final Throwable e) {
super(e.getMessage(), e);
}
public CronException(String message) {
public CronException(final String message) {
super(message);
}
public CronException(String messageTemplate, Object... params) {
public CronException(final String messageTemplate, final Object... params) {
super(StrUtil.format(messageTemplate, params));
}
public CronException(String message, Throwable throwable, boolean enableSuppression, boolean writableStackTrace) {
public CronException(final String message, final Throwable throwable, final boolean enableSuppression, final boolean writableStackTrace) {
super(message, throwable, enableSuppression, writableStackTrace);
}
public CronException(Throwable throwable, String messageTemplate, Object... params) {
public CronException(final Throwable throwable, final String messageTemplate, final Object... params) {
super(StrUtil.format(messageTemplate, params), throwable);
}
}

View File

@@ -22,23 +22,23 @@ public class CronTimer extends Thread implements Serializable {
private final long TIMER_UNIT_SECOND = DateUnit.SECOND.getMillis();
/** 定时单元:分 */
private final long TIMER_UNIT_MINUTE = DateUnit.MINUTE.getMillis();
/** 定时任务是否已经被强制关闭 */
private boolean isStop;
private final Scheduler scheduler;
/**
* 构造
* @param scheduler {@link Scheduler}
*/
public CronTimer(Scheduler scheduler) {
public CronTimer(final Scheduler scheduler) {
this.scheduler = scheduler;
}
@Override
public void run() {
final long timerUnit = this.scheduler.config.matchSecond ? TIMER_UNIT_SECOND : TIMER_UNIT_MINUTE;
long thisTime = System.currentTimeMillis();
long nextTime;
long sleep;
@@ -62,7 +62,7 @@ public class CronTimer extends Thread implements Serializable {
}
log.debug("Hutool-cron timer stopped.");
}
/**
* 关闭定时器
*/
@@ -70,7 +70,7 @@ public class CronTimer extends Thread implements Serializable {
this.isStop = true;
ThreadUtil.interrupt(this, true);
}
/**
* 启动匹配
* @param millis 当前时间
@@ -91,7 +91,7 @@ public class CronTimer extends Thread implements Serializable {
* @return 是否为有效的sleep毫秒数
* @since 5.3.2
*/
private static boolean isValidSleepMillis(long millis, long timerUnit){
private static boolean isValidSleepMillis(final long millis, final long timerUnit){
return millis > 0 &&
// 防止用户向前调整时间导致的长时间sleep
millis < (2 * timerUnit);

View File

@@ -34,7 +34,7 @@ public class CronUtil {
*
* @param cronSetting 定时任务配置文件
*/
public static void setCronSetting(Setting cronSetting) {
public static void setCronSetting(final Setting cronSetting) {
crontabSetting = cronSetting;
}
@@ -43,10 +43,10 @@ public class CronUtil {
*
* @param cronSettingPath 定时任务配置文件路径(相对绝对都可)
*/
public static void setCronSetting(String cronSettingPath) {
public static void setCronSetting(final String cronSettingPath) {
try {
crontabSetting = new Setting(cronSettingPath, Setting.DEFAULT_CHARSET, false);
} catch (SettingRuntimeException | NoResourceException e) {
} catch (final SettingRuntimeException | NoResourceException e) {
// ignore setting file parse error and no config error
}
}
@@ -57,7 +57,7 @@ public class CronUtil {
*
* @param isMatchSecond {@code true}支持,{@code false}不支持
*/
public static void setMatchSecond(boolean isMatchSecond) {
public static void setMatchSecond(final boolean isMatchSecond) {
scheduler.setMatchSecond(isMatchSecond);
}
@@ -68,7 +68,7 @@ public class CronUtil {
* @param task 任务
* @return 定时任务ID
*/
public static String schedule(String schedulingPattern, Task task) {
public static String schedule(final String schedulingPattern, final Task task) {
return scheduler.schedule(schedulingPattern, task);
}
@@ -81,7 +81,7 @@ public class CronUtil {
* @return 定时任务ID
* @since 3.3.0
*/
public static String schedule(String id, String schedulingPattern, Task task) {
public static String schedule(final String id, final String schedulingPattern, final Task task) {
scheduler.schedule(id, schedulingPattern, task);
return id;
}
@@ -93,7 +93,7 @@ public class CronUtil {
* @param task 任务
* @return 定时任务ID
*/
public static String schedule(String schedulingPattern, Runnable task) {
public static String schedule(final String schedulingPattern, final Runnable task) {
return scheduler.schedule(schedulingPattern, task);
}
@@ -102,7 +102,7 @@ public class CronUtil {
*
* @param cronSetting 定时任务设置文件
*/
public static void schedule(Setting cronSetting) {
public static void schedule(final Setting cronSetting) {
scheduler.schedule(cronSetting);
}
@@ -112,7 +112,7 @@ public class CronUtil {
* @param schedulerId 任务ID
* @return 是否移除成功,{@code false}表示未找到对应ID的任务
*/
public static boolean remove(String schedulerId) {
public static boolean remove(final String schedulerId) {
return scheduler.descheduleWithStatus(schedulerId);
}
@@ -123,7 +123,7 @@ public class CronUtil {
* @param pattern {@link CronPattern}
* @since 4.0.10
*/
public static void updatePattern(String id, CronPattern pattern) {
public static void updatePattern(final String id, final CronPattern pattern) {
scheduler.updatePattern(id, pattern);
}
@@ -148,7 +148,7 @@ public class CronUtil {
*
* @param isDaemon 是否以守护线程方式启动如果为true则在调用{@link #stop()}方法后执行的定时任务立即结束,否则等待执行完毕才结束。
*/
synchronized public static void start(boolean isDaemon) {
synchronized public static void start(final boolean isDaemon) {
if (scheduler.isStarted()) {
throw new UtilException("Scheduler has been started, please stop it first!");
}

View File

@@ -84,7 +84,7 @@ public class Scheduler implements Serializable {
* @param timeZone 时区
* @return this
*/
public Scheduler setTimeZone(TimeZone timeZone) {
public Scheduler setTimeZone(final TimeZone timeZone) {
this.config.setTimeZone(timeZone);
return this;
}
@@ -107,7 +107,7 @@ public class Scheduler implements Serializable {
* @return this
* @throws CronException 定时任务已经启动抛出此异常
*/
public Scheduler setDaemon(boolean on) throws CronException {
public Scheduler setDaemon(final boolean on) throws CronException {
lock.lock();
try {
checkStarted();
@@ -127,7 +127,7 @@ public class Scheduler implements Serializable {
* @throws CronException 定时任务已经启动抛出此异常
* @since 5.7.10
*/
public Scheduler setThreadExecutor(ExecutorService threadExecutor) throws CronException {
public Scheduler setThreadExecutor(final ExecutorService threadExecutor) throws CronException {
lock.lock();
try {
checkStarted();
@@ -162,7 +162,7 @@ public class Scheduler implements Serializable {
* @param isMatchSecond {@code true}支持,{@code false}不支持
* @return this
*/
public Scheduler setMatchSecond(boolean isMatchSecond) {
public Scheduler setMatchSecond(final boolean isMatchSecond) {
this.config.setMatchSecond(isMatchSecond);
return this;
}
@@ -173,7 +173,7 @@ public class Scheduler implements Serializable {
* @param listener {@link TaskListener}
* @return this
*/
public Scheduler addListener(TaskListener listener) {
public Scheduler addListener(final TaskListener listener) {
this.listenerManager.addListener(listener);
return this;
}
@@ -184,7 +184,7 @@ public class Scheduler implements Serializable {
* @param listener {@link TaskListener}
* @return this
*/
public Scheduler removeListener(TaskListener listener) {
public Scheduler removeListener(final TaskListener listener) {
this.listenerManager.removeListener(listener);
return this;
}
@@ -198,12 +198,12 @@ public class Scheduler implements Serializable {
* @param cronSetting 定时任务设置文件
* @return this
*/
public Scheduler schedule(Setting cronSetting) {
public Scheduler schedule(final Setting cronSetting) {
if (MapUtil.isNotEmpty(cronSetting)) {
String group;
for (Entry<String, LinkedHashMap<String, String>> groupedEntry : cronSetting.getGroupedMap().entrySet()) {
for (final Entry<String, LinkedHashMap<String, String>> groupedEntry : cronSetting.getGroupedMap().entrySet()) {
group = groupedEntry.getKey();
for (Entry<String, String> entry : groupedEntry.getValue().entrySet()) {
for (final Entry<String, String> entry : groupedEntry.getValue().entrySet()) {
String jobClass = entry.getKey();
if (StrUtil.isNotBlank(group)) {
jobClass = group + CharUtil.DOT + jobClass;
@@ -212,7 +212,7 @@ public class Scheduler implements Serializable {
StaticLog.debug("Load job: {} {}", pattern, jobClass);
try {
schedule(pattern, new InvokeTask(jobClass));
} catch (Exception e) {
} catch (final Exception e) {
throw new CronException(e, "Schedule [{}] [{}] error!", pattern, jobClass);
}
}
@@ -228,7 +228,7 @@ public class Scheduler implements Serializable {
* @param task {@link Runnable}
* @return ID
*/
public String schedule(String pattern, Runnable task) {
public String schedule(final String pattern, final Runnable task) {
return schedule(pattern, new RunnableTask(task));
}
@@ -239,8 +239,8 @@ public class Scheduler implements Serializable {
* @param task {@link Task}
* @return ID
*/
public String schedule(String pattern, Task task) {
String id = IdUtil.fastUUID();
public String schedule(final String pattern, final Task task) {
final String id = IdUtil.fastUUID();
schedule(id, pattern, task);
return id;
}
@@ -253,7 +253,7 @@ public class Scheduler implements Serializable {
* @param task {@link Runnable}
* @return this
*/
public Scheduler schedule(String id, String pattern, Runnable task) {
public Scheduler schedule(final String id, final String pattern, final Runnable task) {
return schedule(id, new CronPattern(pattern), new RunnableTask(task));
}
@@ -265,7 +265,7 @@ public class Scheduler implements Serializable {
* @param task {@link Task}
* @return this
*/
public Scheduler schedule(String id, String pattern, Task task) {
public Scheduler schedule(final String id, final String pattern, final Task task) {
return schedule(id, new CronPattern(pattern), task);
}
@@ -277,7 +277,7 @@ public class Scheduler implements Serializable {
* @param task {@link Task}
* @return this
*/
public Scheduler schedule(String id, CronPattern pattern, Task task) {
public Scheduler schedule(final String id, final CronPattern pattern, final Task task) {
taskTable.add(id, pattern, task);
return this;
}
@@ -288,7 +288,7 @@ public class Scheduler implements Serializable {
* @param id Task的ID
* @return this
*/
public Scheduler deschedule(String id) {
public Scheduler deschedule(final String id) {
descheduleWithStatus(id);
return this;
}
@@ -300,7 +300,7 @@ public class Scheduler implements Serializable {
* @return 是否移除成功,{@code false}表示未找到对应ID的任务
* @since 5.7.17
*/
public boolean descheduleWithStatus(String id) {
public boolean descheduleWithStatus(final String id) {
return this.taskTable.remove(id);
}
@@ -312,7 +312,7 @@ public class Scheduler implements Serializable {
* @return this
* @since 4.0.10
*/
public Scheduler updatePattern(String id, CronPattern pattern) {
public Scheduler updatePattern(final String id, final CronPattern pattern) {
this.taskTable.updatePattern(id, pattern);
return this;
}
@@ -334,7 +334,7 @@ public class Scheduler implements Serializable {
* @return {@link CronPattern}
* @since 3.1.1
*/
public CronPattern getPattern(String id) {
public CronPattern getPattern(final String id) {
return this.taskTable.getPattern(id);
}
@@ -345,7 +345,7 @@ public class Scheduler implements Serializable {
* @return {@link Task}
* @since 3.1.1
*/
public Task getTask(String id) {
public Task getTask(final String id) {
return this.taskTable.getTask(id);
}
@@ -393,7 +393,7 @@ public class Scheduler implements Serializable {
* @param isDaemon 是否以守护线程方式启动如果为true则在调用{@link #stop()}方法后执行的定时任务立即结束,否则等待执行完毕才结束。
* @return this
*/
public Scheduler start(boolean isDaemon) {
public Scheduler start(final boolean isDaemon) {
this.daemon = isDaemon;
return start();
}
@@ -447,7 +447,7 @@ public class Scheduler implements Serializable {
* @return this
* @since 4.1.17
*/
public Scheduler stop(boolean clearTasks) {
public Scheduler stop(final boolean clearTasks) {
lock.lock();
try {
if (false == started) {

View File

@@ -40,7 +40,7 @@ public class TaskExecutor implements Runnable {
* @param scheduler 调度器
* @param task 被执行的任务
*/
public TaskExecutor(Scheduler scheduler, CronTask task) {
public TaskExecutor(final Scheduler scheduler, final CronTask task) {
this.scheduler = scheduler;
this.task = task;
}
@@ -51,7 +51,7 @@ public class TaskExecutor implements Runnable {
scheduler.listenerManager.notifyTaskStart(this);
task.execute();
scheduler.listenerManager.notifyTaskSucceeded(this);
} catch (Exception e) {
} catch (final Exception e) {
scheduler.listenerManager.notifyTaskFailed(this, e);
} finally {
scheduler.taskExecutorManager.notifyExecutorCompleted(this);

View File

@@ -28,7 +28,7 @@ public class TaskExecutorManager implements Serializable {
*/
private final List<TaskExecutor> executors = new ArrayList<>();
public TaskExecutorManager(Scheduler scheduler) {
public TaskExecutorManager(final Scheduler scheduler) {
this.scheduler = scheduler;
}
@@ -48,7 +48,7 @@ public class TaskExecutorManager implements Serializable {
* @param task {@link Task}
* @return {@link TaskExecutor}
*/
public TaskExecutor spawnExecutor(CronTask task) {
public TaskExecutor spawnExecutor(final CronTask task) {
final TaskExecutor executor = new TaskExecutor(this.scheduler, task);
synchronized (this.executors) {
this.executors.add(executor);
@@ -66,7 +66,7 @@ public class TaskExecutorManager implements Serializable {
* @param executor 执行器 {@link TaskExecutor}
* @return this
*/
public TaskExecutorManager notifyExecutorCompleted(TaskExecutor executor) {
public TaskExecutorManager notifyExecutorCompleted(final TaskExecutor executor) {
synchronized (executors) {
executors.remove(executor);
}

View File

@@ -18,7 +18,7 @@ public class TaskLauncher implements Runnable {
* @param scheduler {@link Scheduler}
* @param millis 毫秒数
*/
public TaskLauncher(Scheduler scheduler, long millis) {
public TaskLauncher(final Scheduler scheduler, final long millis) {
this.scheduler = scheduler;
this.millis = millis;
}

View File

@@ -17,7 +17,7 @@ public class TaskLauncherManager implements Serializable {
/** 启动器列表 */
protected final List<TaskLauncher> launchers = new ArrayList<>();
public TaskLauncherManager(Scheduler scheduler) {
public TaskLauncherManager(final Scheduler scheduler) {
this.scheduler = scheduler;
}
@@ -26,7 +26,7 @@ public class TaskLauncherManager implements Serializable {
* @param millis 触发事件的毫秒数
* @return {@link TaskLauncher}
*/
protected TaskLauncher spawnLauncher(long millis) {
protected TaskLauncher spawnLauncher(final long millis) {
final TaskLauncher launcher = new TaskLauncher(this.scheduler, millis);
synchronized (this.launchers) {
this.launchers.add(launcher);
@@ -42,7 +42,7 @@ public class TaskLauncherManager implements Serializable {
* 启动器启动完毕,启动完毕后从执行器列表中移除
* @param launcher 启动器 {@link TaskLauncher}
*/
protected void notifyLauncherCompleted(TaskLauncher launcher) {
protected void notifyLauncherCompleted(final TaskLauncher launcher) {
synchronized (launchers) {
launchers.remove(launcher);
}

View File

@@ -44,7 +44,7 @@ public class TaskTable implements Serializable {
*
* @param initialCapacity 容量,即预估的最大任务数
*/
public TaskTable(int initialCapacity) {
public TaskTable(final int initialCapacity) {
lock = new ReentrantReadWriteLock();
ids = new ArrayList<>(initialCapacity);
@@ -60,7 +60,7 @@ public class TaskTable implements Serializable {
* @param task {@link Task}
* @return this
*/
public TaskTable add(String id, CronPattern pattern, Task task) {
public TaskTable add(final String id, final CronPattern pattern, final Task task) {
final Lock writeLock = lock.writeLock();
writeLock.lock();
try {
@@ -131,7 +131,7 @@ public class TaskTable implements Serializable {
* @param id Task的ID
* @return 是否成功移除,{@code false}表示未找到对应ID的任务
*/
public boolean remove(String id) {
public boolean remove(final String id) {
final Lock writeLock = lock.writeLock();
writeLock.lock();
try {
@@ -157,7 +157,7 @@ public class TaskTable implements Serializable {
* @return 是否更新成功如果id对应的规则不存在则不更新
* @since 4.0.10
*/
public boolean updatePattern(String id, CronPattern pattern) {
public boolean updatePattern(final String id, final CronPattern pattern) {
final Lock writeLock = lock.writeLock();
writeLock.lock();
try {
@@ -179,7 +179,7 @@ public class TaskTable implements Serializable {
* @return {@link Task}
* @since 3.1.1
*/
public Task getTask(int index) {
public Task getTask(final int index) {
final Lock readLock = lock.readLock();
readLock.lock();
try {
@@ -196,7 +196,7 @@ public class TaskTable implements Serializable {
* @return {@link Task}
* @since 3.1.1
*/
public Task getTask(String id) {
public Task getTask(final String id) {
final int index = ids.indexOf(id);
if (index > -1) {
return getTask(index);
@@ -211,7 +211,7 @@ public class TaskTable implements Serializable {
* @return {@link CronPattern}
* @since 3.1.1
*/
public CronPattern getPattern(int index) {
public CronPattern getPattern(final int index) {
final Lock readLock = lock.readLock();
readLock.lock();
try {
@@ -248,7 +248,7 @@ public class TaskTable implements Serializable {
* @return {@link CronPattern}
* @since 3.1.1
*/
public CronPattern getPattern(String id) {
public CronPattern getPattern(final String id) {
final int index = ids.indexOf(id);
if (index > -1) {
return getPattern(index);
@@ -262,7 +262,7 @@ public class TaskTable implements Serializable {
* @param scheduler {@link Scheduler}
* @param millis 时间毫秒
*/
public void executeTaskIfMatch(Scheduler scheduler, long millis) {
public void executeTaskIfMatch(final Scheduler scheduler, final long millis) {
final Lock readLock = lock.readLock();
readLock.lock();
try {
@@ -289,7 +289,7 @@ public class TaskTable implements Serializable {
* @param millis 时间毫秒
* @since 3.1.1
*/
protected void executeTaskIfMatchInternal(Scheduler scheduler, long millis) {
protected void executeTaskIfMatchInternal(final Scheduler scheduler, final long millis) {
for (int i = 0; i < size; i++) {
if (patterns.get(i).match(scheduler.config.timezone, millis, scheduler.config.matchSecond)) {
scheduler.taskExecutorManager.spawnExecutor(new CronTask(ids.get(i), patterns.get(i), tasks.get(i)));

View File

@@ -11,15 +11,15 @@ import cn.hutool.cron.TaskExecutor;
public class SimpleTaskListener implements TaskListener{
@Override
public void onStart(TaskExecutor executor) {
public void onStart(final TaskExecutor executor) {
}
@Override
public void onSucceeded(TaskExecutor executor) {
public void onSucceeded(final TaskExecutor executor) {
}
@Override
public void onFailed(TaskExecutor executor, Throwable exception) {
public void onFailed(final TaskExecutor executor, final Throwable exception) {
}
}

View File

@@ -22,7 +22,7 @@ public class TaskListenerManager implements Serializable {
* @param listener {@link TaskListener}
* @return this
*/
public TaskListenerManager addListener(TaskListener listener){
public TaskListenerManager addListener(final TaskListener listener){
synchronized (listeners) {
this.listeners.add(listener);
}
@@ -34,7 +34,7 @@ public class TaskListenerManager implements Serializable {
* @param listener {@link TaskListener}
* @return this
*/
public TaskListenerManager removeListener(TaskListener listener){
public TaskListenerManager removeListener(final TaskListener listener){
synchronized (listeners) {
this.listeners.remove(listener);
}
@@ -45,10 +45,10 @@ public class TaskListenerManager implements Serializable {
* 通知所有监听任务启动器启动
* @param executor {@link TaskExecutor}
*/
public void notifyTaskStart(TaskExecutor executor) {
public void notifyTaskStart(final TaskExecutor executor) {
synchronized (listeners) {
TaskListener listener;
for (TaskListener taskListener : listeners) {
for (final TaskListener taskListener : listeners) {
listener = taskListener;
if (null != listener) {
listener.onStart(executor);
@@ -61,9 +61,9 @@ public class TaskListenerManager implements Serializable {
* 通知所有监听任务启动器成功结束
* @param executor {@link TaskExecutor}
*/
public void notifyTaskSucceeded(TaskExecutor executor) {
public void notifyTaskSucceeded(final TaskExecutor executor) {
synchronized (listeners) {
for (TaskListener listener : listeners) {
for (final TaskListener listener : listeners) {
listener.onSucceeded(executor);
}
}
@@ -75,11 +75,11 @@ public class TaskListenerManager implements Serializable {
* @param executor {@link TaskExecutor}
* @param exception 失败原因
*/
public void notifyTaskFailed(TaskExecutor executor, Throwable exception) {
public void notifyTaskFailed(final TaskExecutor executor, final Throwable exception) {
synchronized (listeners) {
int size = listeners.size();
final int size = listeners.size();
if(size > 0){
for (TaskListener listener : listeners) {
for (final TaskListener listener : listeners) {
listener.onFailed(executor, exception);
}
}else{

View File

@@ -80,7 +80,7 @@ public class CronPattern {
* @return CronPattern
* @since 5.8.0
*/
public static CronPattern of(String pattern) {
public static CronPattern of(final String pattern) {
return new CronPattern(pattern);
}
@@ -89,7 +89,7 @@ public class CronPattern {
*
* @param pattern 表达式
*/
public CronPattern(String pattern) {
public CronPattern(final String pattern) {
this.pattern = pattern;
this.matchers = PatternParser.parse(pattern);
}
@@ -101,7 +101,7 @@ public class CronPattern {
* @param isMatchSecond 是否匹配秒
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
*/
public boolean match(long millis, boolean isMatchSecond) {
public boolean match(final long millis, final boolean isMatchSecond) {
return match(TimeZone.getDefault(), millis, isMatchSecond);
}
@@ -113,7 +113,7 @@ public class CronPattern {
* @param isMatchSecond 是否匹配秒
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
*/
public boolean match(TimeZone timezone, long millis, boolean isMatchSecond) {
public boolean match(final TimeZone timezone, final long millis, final boolean isMatchSecond) {
final GregorianCalendar calendar = new GregorianCalendar(timezone);
calendar.setTimeInMillis(millis);
return match(calendar, isMatchSecond);
@@ -126,7 +126,7 @@ public class CronPattern {
* @param isMatchSecond 是否匹配秒
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
*/
public boolean match(Calendar calendar, boolean isMatchSecond) {
public boolean match(final Calendar calendar, final boolean isMatchSecond) {
return match(PatternUtil.getFields(calendar, isMatchSecond));
}
@@ -138,7 +138,7 @@ public class CronPattern {
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
* @since 5.8.0
*/
public boolean match(LocalDateTime dateTime, boolean isMatchSecond) {
public boolean match(final LocalDateTime dateTime, final boolean isMatchSecond) {
return match(PatternUtil.getFields(dateTime, isMatchSecond));
}
@@ -148,7 +148,7 @@ public class CronPattern {
* @param calendar 时间
* @return 匹配到的下一个时间
*/
public Calendar nextMatchAfter(Calendar calendar) {
public Calendar nextMatchAfter(final Calendar calendar) {
Calendar next = nextMatchAfter(PatternUtil.getFields(calendar, true), calendar.getTimeZone());
if (false == match(next, true)) {
next.set(Calendar.DAY_OF_MONTH, next.get(Calendar.DAY_OF_MONTH) + 1);
@@ -169,8 +169,8 @@ public class CronPattern {
* @param fields 时间字段值,{second, minute, hour, dayOfMonth, month, dayOfWeek, year}
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
*/
private boolean match(int[] fields) {
for (PatternMatcher matcher : matchers) {
private boolean match(final int[] fields) {
for (final PatternMatcher matcher : matchers) {
if (matcher.match(fields)) {
return true;
}
@@ -185,9 +185,9 @@ public class CronPattern {
* @param zone 时区
* @return {@link Calendar}毫秒数为0
*/
private Calendar nextMatchAfter(int[] values, TimeZone zone) {
private Calendar nextMatchAfter(final int[] values, final TimeZone zone) {
final List<Calendar> nextMatches = new ArrayList<>(matchers.size());
for (PatternMatcher matcher : matchers) {
for (final PatternMatcher matcher : matchers) {
nextMatches.add(matcher.nextMatchAfter(values, zone));
}
// 返回匹配到的最早日期

View File

@@ -32,8 +32,8 @@ public class CronPatternBuilder implements Builder<String> {
* @param values 时间值列表
* @return this
*/
public CronPatternBuilder setValues(Part part, int... values) {
for (int value : values) {
public CronPatternBuilder setValues(final Part part, final int... values) {
for (final int value : values) {
part.checkValue(value);
}
return set(part, ArrayUtil.join(values, ","));
@@ -47,7 +47,7 @@ public class CronPatternBuilder implements Builder<String> {
* @param end 结束值
* @return this
*/
public CronPatternBuilder setRange(Part part, int begin, int end) {
public CronPatternBuilder setRange(final Part part, final int begin, final int end) {
Assert.notNull(part );
part.checkValue(begin);
part.checkValue(end);
@@ -61,7 +61,7 @@ public class CronPatternBuilder implements Builder<String> {
* @param value 表达式值,如"*"、"1,2"、"5-12"等
* @return this
*/
public CronPatternBuilder set(Part part, String value) {
public CronPatternBuilder set(final Part part, final String value) {
parts[part.ordinal()] = value;
return this;
}

View File

@@ -26,8 +26,8 @@ public class CronPatternUtil {
* @return 日期
* @since 4.5.8
*/
public static Date nextDateAfter(CronPattern pattern, Date start, boolean isMatchSecond) {
List<Date> matchedDates = matchedDates(pattern, start.getTime(), DateUtil.endOfYear(start).getTime(), 1, isMatchSecond);
public static Date nextDateAfter(final CronPattern pattern, final Date start, final boolean isMatchSecond) {
final List<Date> matchedDates = matchedDates(pattern, start.getTime(), DateUtil.endOfYear(start).getTime(), 1, isMatchSecond);
if (CollUtil.isNotEmpty(matchedDates)) {
return matchedDates.get(0);
}
@@ -43,7 +43,7 @@ public class CronPatternUtil {
* @param isMatchSecond 是否匹配秒
* @return 日期列表
*/
public static List<Date> matchedDates(String patternStr, Date start, int count, boolean isMatchSecond) {
public static List<Date> matchedDates(final String patternStr, final Date start, final int count, final boolean isMatchSecond) {
return matchedDates(patternStr, start, DateUtil.endOfYear(start), count, isMatchSecond);
}
@@ -57,7 +57,7 @@ public class CronPatternUtil {
* @param isMatchSecond 是否匹配秒
* @return 日期列表
*/
public static List<Date> matchedDates(String patternStr, Date start, Date end, int count, boolean isMatchSecond) {
public static List<Date> matchedDates(final String patternStr, final Date start, final Date end, final int count, final boolean isMatchSecond) {
return matchedDates(patternStr, start.getTime(), end.getTime(), count, isMatchSecond);
}
@@ -71,7 +71,7 @@ public class CronPatternUtil {
* @param isMatchSecond 是否匹配秒
* @return 日期列表
*/
public static List<Date> matchedDates(String patternStr, long start, long end, int count, boolean isMatchSecond) {
public static List<Date> matchedDates(final String patternStr, final long start, final long end, final int count, final boolean isMatchSecond) {
return matchedDates(new CronPattern(patternStr), start, end, count, isMatchSecond);
}
@@ -85,11 +85,11 @@ public class CronPatternUtil {
* @param isMatchSecond 是否匹配秒
* @return 日期列表
*/
public static List<Date> matchedDates(CronPattern pattern, long start, long end, int count, boolean isMatchSecond) {
public static List<Date> matchedDates(final CronPattern pattern, final long start, final long end, final int count, final boolean isMatchSecond) {
Assert.isTrue(start < end, "Start date is later than end !");
final List<Date> result = new ArrayList<>(count);
long step = isMatchSecond ? DateUnit.SECOND.getMillis() : DateUnit.MINUTE.getMillis();
final long step = isMatchSecond ? DateUnit.SECOND.getMillis() : DateUnit.MINUTE.getMillis();
for (long i = start; i < end; i += step) {
if (pattern.match(i, isMatchSecond)) {
result.add(DateUtil.date(i));

View File

@@ -42,7 +42,7 @@ public enum Part {
* @param min 限定最小值(包含)
* @param max 限定最大值(包含)
*/
Part(int calendarField, int min, int max) {
Part(final int calendarField, final int min, final int max) {
this.calendarField = calendarField;
if (min > max) {
this.min = max;
@@ -87,7 +87,7 @@ public enum Part {
* @return 检查后的值
* @throws CronException 检查无效抛出此异常
*/
public int checkValue(int value) throws CronException {
public int checkValue(final int value) throws CronException {
Assert.checkBetween(value, min, max,
() -> new CronException("Value {} out of range: [{} , {}]", value, min, max));
return value;
@@ -99,7 +99,7 @@ public enum Part {
* @param i 位置从0开始
* @return Part
*/
public static Part of(int i) {
public static Part of(final int i) {
return ENUMS[i];
}
}

View File

@@ -22,7 +22,7 @@ class PatternUtil {
* @return 字段值列表
* @since 5.8.0
*/
static int[] getFields(LocalDateTime dateTime, boolean isMatchSecond) {
static int[] getFields(final LocalDateTime dateTime, final boolean isMatchSecond) {
final int second = isMatchSecond ? dateTime.getSecond() : -1;
final int minute = dateTime.getMinute();
final int hour = dateTime.getHour();
@@ -42,7 +42,7 @@ class PatternUtil {
* @return 字段值列表
* @since 5.8.0
*/
static int[] getFields(Calendar calendar, boolean isMatchSecond) {
static int[] getFields(final Calendar calendar, final boolean isMatchSecond) {
final int second = isMatchSecond ? calendar.get(Calendar.SECOND) : -1;
final int minute = calendar.get(Calendar.MINUTE);
final int hour = calendar.get(Calendar.HOUR_OF_DAY);

View File

@@ -12,12 +12,12 @@ public class AlwaysTrueMatcher implements PartMatcher {
public static AlwaysTrueMatcher INSTANCE = new AlwaysTrueMatcher();
@Override
public boolean match(Integer t) {
public boolean match(final Integer t) {
return true;
}
@Override
public int nextAfter(int value) {
public int nextAfter(final int value) {
return value;
}

View File

@@ -25,11 +25,11 @@ public class BoolArrayMatcher implements PartMatcher {
*
* @param intValueList 匹配值列表
*/
public BoolArrayMatcher(List<Integer> intValueList) {
public BoolArrayMatcher(final List<Integer> intValueList) {
Assert.isTrue(CollUtil.isNotEmpty(intValueList), "Values must be not empty!");
bValues = new boolean[Collections.max(intValueList) + 1];
int min = Integer.MAX_VALUE;
for (Integer value : intValueList) {
for (final Integer value : intValueList) {
min = Math.min(min, value);
bValues[value] = true;
}
@@ -37,7 +37,7 @@ public class BoolArrayMatcher implements PartMatcher {
}
@Override
public boolean match(Integer value) {
public boolean match(final Integer value) {
if (null == value || value >= bValues.length) {
return false;
}

View File

@@ -17,7 +17,7 @@ public class DayOfMonthMatcher extends BoolArrayMatcher {
*
* @param intValueList 匹配的日值
*/
public DayOfMonthMatcher(List<Integer> intValueList) {
public DayOfMonthMatcher(final List<Integer> intValueList) {
super(intValueList);
}
@@ -29,7 +29,7 @@ public class DayOfMonthMatcher extends BoolArrayMatcher {
* @param isLeapYear 是否闰年
* @return 是否匹配
*/
public boolean match(int value, int month, boolean isLeapYear) {
public boolean match(final int value, final int month, final boolean isLeapYear) {
return (super.match(value) // 在约定日范围内的某一天
//匹配器中用户定义了最后一天31表示最后一天
|| (value > 27 && match(31) && isLastDayOfMonth(value, month, isLeapYear)));
@@ -47,7 +47,7 @@ public class DayOfMonthMatcher extends BoolArrayMatcher {
* @param isLeapYear 是否闰年
* @return 是否为本月最后一天
*/
private static boolean isLastDayOfMonth(int value, int month, boolean isLeapYear) {
private static boolean isLastDayOfMonth(final int value, final int month, final boolean isLeapYear) {
return value == Month.getLastDay(month - 1, isLeapYear);
}
}

View File

@@ -31,13 +31,13 @@ public class PatternMatcher {
* @param dayOfWeekMatcher 周匹配器
* @param yearMatcher 年匹配器
*/
public PatternMatcher(PartMatcher secondMatcher,
PartMatcher minuteMatcher,
PartMatcher hourMatcher,
PartMatcher dayOfMonthMatcher,
PartMatcher monthMatcher,
PartMatcher dayOfWeekMatcher,
PartMatcher yearMatcher) {
public PatternMatcher(final PartMatcher secondMatcher,
final PartMatcher minuteMatcher,
final PartMatcher hourMatcher,
final PartMatcher dayOfMonthMatcher,
final PartMatcher monthMatcher,
final PartMatcher dayOfWeekMatcher,
final PartMatcher yearMatcher) {
matchers = new PartMatcher[]{
secondMatcher,
@@ -56,7 +56,7 @@ public class PatternMatcher {
* @param part 表达式位置
* @return {@link PartMatcher}
*/
public PartMatcher get(Part part) {
public PartMatcher get(final Part part) {
return matchers[part.ordinal()];
}
@@ -68,7 +68,7 @@ public class PatternMatcher {
* @param fields 时间字段值,{second, minute, hour, dayOfMonth, month, dayOfWeek, year}
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
*/
public boolean match(int[] fields) {
public boolean match(final int[] fields) {
return match(fields[0], fields[1], fields[2], fields[3], fields[4], fields[5], fields[6]);
}
@@ -79,7 +79,7 @@ public class PatternMatcher {
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
* @since 5.8.0
*/
public boolean matchWeek(int dayOfWeekValue) {
public boolean matchWeek(final int dayOfWeekValue) {
return matchers[5].match(dayOfWeekValue);
}
@@ -95,7 +95,7 @@ public class PatternMatcher {
* @param year 年
* @return 如果匹配返回 {@code true}, 否则返回 {@code false}
*/
private boolean match(int second, int minute, int hour, int dayOfMonth, int month, int dayOfWeek, int year) {
private boolean match(final int second, final int minute, final int hour, final int dayOfMonth, final int month, final int dayOfWeek, final int year) {
return ((second < 0) || matchers[0].match(second)) // 匹配秒非秒匹配模式下始终返回true
&& matchers[1].match(minute)// 匹配分
&& matchers[2].match(hour)// 匹配时
@@ -114,7 +114,7 @@ public class PatternMatcher {
* @param isLeapYear 是否闰年
* @return 是否匹配
*/
private static boolean matchDayOfMonth(PartMatcher matcher, int dayOfMonth, int month, boolean isLeapYear) {
private static boolean matchDayOfMonth(final PartMatcher matcher, final int dayOfMonth, final int month, final boolean isLeapYear) {
return ((matcher instanceof DayOfMonthMatcher) //
? ((DayOfMonthMatcher) matcher).match(dayOfMonth, month, isLeapYear) //
: matcher.match(dayOfMonth));
@@ -141,7 +141,7 @@ public class PatternMatcher {
* @param zone 时区
* @return {@link Calendar}毫秒数为0
*/
public Calendar nextMatchAfter(int[] values, TimeZone zone) {
public Calendar nextMatchAfter(final int[] values, final TimeZone zone) {
final Calendar calendar = Calendar.getInstance(zone);
calendar.set(Calendar.MILLISECOND, 0);
@@ -173,7 +173,7 @@ public class PatternMatcher {
* @param values 时间字段值,{second, minute, hour, dayOfMonth, month, dayOfWeek, year}
* @return {@link Calendar}毫秒数为0
*/
private int[] nextMatchValuesAfter(int[] values) {
private int[] nextMatchValuesAfter(final int[] values) {
final int[] newValues = values.clone();
int i = Part.YEAR.ordinal();
@@ -230,7 +230,7 @@ public class PatternMatcher {
* @param values 值数组
* @param toPart 截止的部分
*/
private void setToMin(int[] values, int toPart) {
private void setToMin(final int[] values, final int toPart) {
Part part;
for (int i = 0; i <= toPart; i++) {
part = Part.of(i);
@@ -244,10 +244,10 @@ public class PatternMatcher {
* @param part {@link Part}
* @return 最小值,如果匹配所有,返回对应部分范围的最小值
*/
private int getMin(Part part) {
PartMatcher matcher = get(part);
private int getMin(final Part part) {
final PartMatcher matcher = get(part);
int min;
final int min;
if (matcher instanceof AlwaysTrueMatcher) {
min = part.getMin();
} else if (matcher instanceof BoolArrayMatcher) {
@@ -271,7 +271,7 @@ public class PatternMatcher {
* @param value 值
* @return {@link Calendar}
*/
private Calendar setValue(Calendar calendar, Part part, int value) {
private Calendar setValue(final Calendar calendar, final Part part, int value) {
switch (part) {
case MONTH:
value -= 1;

View File

@@ -13,18 +13,18 @@ public class YearValueMatcher implements PartMatcher {
private final LinkedHashSet<Integer> valueList;
public YearValueMatcher(Collection<Integer> intValueList) {
public YearValueMatcher(final Collection<Integer> intValueList) {
this.valueList = new LinkedHashSet<>(intValueList);
}
@Override
public boolean match(Integer t) {
public boolean match(final Integer t) {
return valueList.contains(t);
}
@Override
public int nextAfter(int value) {
for (Integer year : valueList) {
public int nextAfter(final int value) {
for (final Integer year : valueList) {
if (year >= value) {
return year;
}

View File

@@ -43,7 +43,7 @@ public class PartParser {
* @param part 对应解析的部分枚举
* @return 解析器
*/
public static PartParser of(Part part) {
public static PartParser of(final Part part) {
return new PartParser(part);
}
@@ -51,7 +51,7 @@ public class PartParser {
* 构造
* @param part 对应解析的部分枚举
*/
public PartParser(Part part) {
public PartParser(final Part part) {
this.part = part;
}
@@ -67,7 +67,7 @@ public class PartParser {
* @param value 表达式
* @return {@link PartMatcher}
*/
public PartMatcher parse(String value) {
public PartMatcher parse(final String value) {
if (isMatchAllStr(value)) {
//兼容Quartz的"?"表达式,不会出现互斥情况,与"*"作用相同
return new AlwaysTrueMatcher();
@@ -99,11 +99,11 @@ public class PartParser {
* @param value 子表达式值
* @return 值列表
*/
private List<Integer> parseArray(String value) {
private List<Integer> parseArray(final String value) {
final List<Integer> values = new ArrayList<>();
final List<String> parts = StrUtil.split(value, StrUtil.C_COMMA);
for (String part : parts) {
for (final String part : parts) {
CollUtil.addAllIfNotContains(values, parseStep(part));
}
return values;
@@ -121,11 +121,11 @@ public class PartParser {
* @param value 表达式值
* @return List
*/
private List<Integer> parseStep(String value) {
private List<Integer> parseStep(final String value) {
final List<String> parts = StrUtil.split(value, StrUtil.C_SLASH);
int size = parts.size();
final int size = parts.size();
List<Integer> results;
final List<Integer> results;
if (size == 1) {// 普通形式
results = parseRange(value, -1);
} else if (size == 2) {// 间隔形式
@@ -154,7 +154,7 @@ public class PartParser {
* @param step 步进
* @return List
*/
private List<Integer> parseRange(String value, int step) {
private List<Integer> parseRange(final String value, int step) {
final List<Integer> results = new ArrayList<>();
// 全部匹配形式
@@ -186,8 +186,8 @@ public class PartParser {
}
//Range模式
List<String> parts = StrUtil.split(value, '-');
int size = parts.size();
final List<String> parts = StrUtil.split(value, '-');
final int size = parts.size();
if (size == 1) {// 普通值
final int v1 = parseNumber(value);
if (step > 0) {//类似 20/2的形式
@@ -224,7 +224,7 @@ public class PartParser {
* @return 是否为全匹配符
* @since 4.1.18
*/
private static boolean isMatchAllStr(String value) {
private static boolean isMatchAllStr(final String value) {
return (1 == value.length()) && ("*".equals(value) || "?".equals(value));
}
@@ -235,11 +235,11 @@ public class PartParser {
* @return 解析结果
* @throws CronException 当无效数字或无效别名时抛出
*/
private int parseNumber(String value) throws CronException {
private int parseNumber(final String value) throws CronException {
int i;
try {
i = Integer.parseInt(value);
} catch (NumberFormatException ignore) {
} catch (final NumberFormatException ignore) {
i = parseAlias(value);
}
@@ -267,7 +267,7 @@ public class PartParser {
* @return 解析int值
* @throws CronException 无匹配别名时抛出异常
*/
private int parseAlias(String name) throws CronException {
private int parseAlias(final String name) throws CronException {
if ("L".equalsIgnoreCase(name)) {
// L表示最大值
return part.getMax();

View File

@@ -33,7 +33,7 @@ public class PatternParser {
* @param cronPattern 复合表达式
* @return {@link List}
*/
public static List<PatternMatcher> parse(String cronPattern) {
public static List<PatternMatcher> parse(final String cronPattern) {
return parseGroupPattern(cronPattern);
}
@@ -46,10 +46,10 @@ public class PatternParser {
* @param groupPattern 复合表达式
* @return {@link List}
*/
private static List<PatternMatcher> parseGroupPattern(String groupPattern) {
private static List<PatternMatcher> parseGroupPattern(final String groupPattern) {
final List<String> patternList = StrUtil.splitTrim(groupPattern, '|');
final List<PatternMatcher> patternMatchers = new ArrayList<>(patternList.size());
for (String pattern : patternList) {
for (final String pattern : patternList) {
patternMatchers.add(parseSingle(pattern));
}
return patternMatchers;
@@ -61,7 +61,7 @@ public class PatternParser {
* @param pattern 表达式
* @return {@link PatternMatcher}
*/
private static PatternMatcher parseSingle(String pattern) {
private static PatternMatcher parseSingle(final String pattern) {
final String[] parts = pattern.split("\\s+");
Assert.checkBetween(parts.length, 5, 7,
() -> new CronException("Pattern [{}] is invalid, it must be 5-7 parts!", pattern));
@@ -76,7 +76,7 @@ public class PatternParser {
final String secondPart = (1 == offset) ? parts[0] : "0";
// 年
PartMatcher yearMatcher;
final PartMatcher yearMatcher;
if (parts.length == 7) {// 支持年的表达式
yearMatcher = YEAR_VALUE_PARSER.parse(parts[6]);
} else {// 不支持年的表达式,全部匹配

View File

@@ -20,7 +20,7 @@ public class CronTask implements Task{
* @param pattern 表达式
* @param task 作业
*/
public CronTask(String id, CronPattern pattern, Task task) {
public CronTask(final String id, final CronPattern pattern, final Task task) {
this.id = id;
this.pattern = pattern;
this.task = task;
@@ -54,7 +54,7 @@ public class CronTask implements Task{
* @param pattern 表达式
* @return this
*/
public CronTask setPattern(CronPattern pattern){
public CronTask setPattern(final CronPattern pattern){
this.pattern = pattern;
return this;
}

View File

@@ -26,7 +26,7 @@ public class InvokeTask implements Task{
* 构造
* @param classNameWithMethodName 类名与方法名的字符串表示,方法名和类名使用#隔开或者.隔开
*/
public InvokeTask(String classNameWithMethodName) {
public InvokeTask(final String classNameWithMethodName) {
int splitIndex = classNameWithMethodName.lastIndexOf('#');
if(splitIndex <= 0){
splitIndex = classNameWithMethodName.lastIndexOf('.');
@@ -61,7 +61,7 @@ public class InvokeTask implements Task{
public void execute() {
try {
ReflectUtil.invoke(this.obj, this.method);
} catch (UtilException e) {
} catch (final UtilException e) {
throw new CronException(e.getCause());
}
}

View File

@@ -7,8 +7,8 @@ package cn.hutool.cron.task;
*/
public class RunnableTask implements Task{
private final Runnable runnable;
public RunnableTask(Runnable runnable) {
public RunnableTask(final Runnable runnable) {
this.runnable = runnable;
}

View File

@@ -44,7 +44,7 @@ public class SystemTimer {
* @param delayQueueTimeout 执行队列取元素超时时长,单位毫秒
* @return this
*/
public SystemTimer setDelayQueueTimeout(long delayQueueTimeout){
public SystemTimer setDelayQueueTimeout(final long delayQueueTimeout){
this.delayQueueTimeout = delayQueueTimeout;
return this;
}
@@ -78,7 +78,7 @@ public class SystemTimer {
*
* @param timerTask 任务
*/
public void addTask(TimerTask timerTask) {
public void addTask(final TimerTask timerTask) {
//添加失败任务直接执行
if (false == timeWheel.addTask(timerTask)) {
ThreadUtil.execAsync(timerTask.getTask());
@@ -92,14 +92,14 @@ public class SystemTimer {
*/
private boolean advanceClock() {
try {
TimerTaskList timerTaskList = poll();
final TimerTaskList timerTaskList = poll();
if (null != timerTaskList) {
//推进时间
timeWheel.advanceClock(timerTaskList.getExpire());
//执行过期任务(包含降级操作)
timerTaskList.flush(this::addTask);
}
} catch (InterruptedException ignore) {
} catch (final InterruptedException ignore) {
return false;
}
return true;

View File

@@ -43,7 +43,7 @@ public class TimerTask {
* @param task 任务
* @param delayMs 延迟毫秒数(以当前时间为准)
*/
public TimerTask(Runnable task, long delayMs) {
public TimerTask(final Runnable task, final long delayMs) {
this.delayMs = System.currentTimeMillis() + delayMs;
this.task = task;
}

View File

@@ -39,7 +39,7 @@ public class TimerTaskList implements Delayed {
* @param expire 过期时间,单位毫秒
* @return 是否设置成功
*/
public boolean setExpiration(long expire) {
public boolean setExpiration(final long expire) {
return this.expire.getAndSet(expire) != expire;
}
@@ -56,11 +56,11 @@ public class TimerTaskList implements Delayed {
*
* @param timerTask 延迟任务
*/
public void addTask(TimerTask timerTask) {
public void addTask(final TimerTask timerTask) {
synchronized (this) {
if (timerTask.timerTaskList == null) {
timerTask.timerTaskList = this;
TimerTask tail = root.prev;
final TimerTask tail = root.prev;
timerTask.next = root;
timerTask.prev = tail;
tail.next = timerTask;
@@ -74,7 +74,7 @@ public class TimerTaskList implements Delayed {
*
* @param timerTask 任务
*/
public void removeTask(TimerTask timerTask) {
public void removeTask(final TimerTask timerTask) {
synchronized (this) {
if (this.equals(timerTask.timerTaskList)) {
timerTask.next.prev = timerTask.prev;
@@ -91,7 +91,7 @@ public class TimerTaskList implements Delayed {
*
* @param flush 任务处理函数
*/
public synchronized void flush(Consumer<TimerTask> flush) {
public synchronized void flush(final Consumer<TimerTask> flush) {
TimerTask timerTask = root.next;
while (false == timerTask.equals(root)) {
this.removeTask(timerTask);
@@ -102,12 +102,12 @@ public class TimerTaskList implements Delayed {
}
@Override
public long getDelay(TimeUnit unit) {
public long getDelay(final TimeUnit unit) {
return Math.max(0, unit.convert(expire.get() - System.currentTimeMillis(), TimeUnit.MILLISECONDS));
}
@Override
public int compareTo(Delayed o) {
public int compareTo(final Delayed o) {
if (o instanceof TimerTaskList) {
return Long.compare(expire.get(), ((TimerTaskList) o).expire.get());
}

View File

@@ -55,7 +55,7 @@ public class TimingWheel {
* @param wheelSize 时间轮大小
* @param consumer 任务处理器
*/
public TimingWheel(long tickMs, int wheelSize, Consumer<TimerTaskList> consumer) {
public TimingWheel(final long tickMs, final int wheelSize, final Consumer<TimerTaskList> consumer) {
this(tickMs, wheelSize, System.currentTimeMillis(), consumer);
}
@@ -67,7 +67,7 @@ public class TimingWheel {
* @param currentTime 当前时间
* @param consumer 任务处理器
*/
public TimingWheel(long tickMs, int wheelSize, long currentTime, Consumer<TimerTaskList> consumer) {
public TimingWheel(final long tickMs, final int wheelSize, final long currentTime, final Consumer<TimerTaskList> consumer) {
this.tickMs = tickMs;
this.wheelSize = wheelSize;
this.interval = tickMs * wheelSize;
@@ -83,15 +83,15 @@ public class TimingWheel {
* @param timerTask 任务
* @return 是否成功
*/
public boolean addTask(TimerTask timerTask) {
long expiration = timerTask.getDelayMs();
public boolean addTask(final TimerTask timerTask) {
final long expiration = timerTask.getDelayMs();
//过期任务直接执行
if (expiration < currentTime + tickMs) {
return false;
} else if (expiration < currentTime + interval) {
//当前时间轮可以容纳该任务 加入时间槽
long virtualId = expiration / tickMs;
int index = (int) (virtualId % wheelSize);
final long virtualId = expiration / tickMs;
final int index = (int) (virtualId % wheelSize);
StaticLog.debug("tickMs: {} ------index: {} ------expiration: {}", tickMs, index, expiration);
TimerTaskList timerTaskList = timerTaskLists[index];
@@ -106,7 +106,7 @@ public class TimingWheel {
}
} else {
//放到上一层的时间轮
TimingWheel timeWheel = getOverflowWheel();
final TimingWheel timeWheel = getOverflowWheel();
timeWheel.addTask(timerTask);
}
return true;
@@ -117,7 +117,7 @@ public class TimingWheel {
*
* @param timestamp 推进的时间
*/
public void advanceClock(long timestamp) {
public void advanceClock(final long timestamp) {
if (timestamp >= currentTime + tickMs) {
currentTime = timestamp - (timestamp % tickMs);
if (overflowWheel != null) {

View File

@@ -6,11 +6,11 @@ import cn.hutool.cron.CronUtil;
public class AddAndRemoveMainTest {
public static void main(String[] args) {
public static void main(final String[] args) {
CronUtil.setMatchSecond(true);
CronUtil.start(false);
CronUtil.getScheduler().clear();
String id = CronUtil.schedule("*/2 * * * * *", (Runnable) () -> Console.log("task running : 2s"));
final String id = CronUtil.schedule("*/2 * * * * *", (Runnable) () -> Console.log("task running : 2s"));
ThreadUtil.sleep(3000);
CronUtil.remove(id);
Console.log("Task Removed");

View File

@@ -44,17 +44,17 @@ public class CronTest {
public void cronWithListenerTest() {
CronUtil.getScheduler().addListener(new TaskListener() {
@Override
public void onStart(TaskExecutor executor) {
public void onStart(final TaskExecutor executor) {
Console.log("Found task:[{}] start!", executor.getCronTask().getId());
}
@Override
public void onSucceeded(TaskExecutor executor) {
public void onSucceeded(final TaskExecutor executor) {
Console.log("Found task:[{}] success!", executor.getCronTask().getId());
}
@Override
public void onFailed(TaskExecutor executor, Throwable exception) {
public void onFailed(final TaskExecutor executor, final Throwable exception) {
Console.error("Found task:[{}] failed!", executor.getCronTask().getId());
}
});
@@ -70,7 +70,7 @@ public class CronTest {
@Test
@Ignore
public void addAndRemoveTest() {
String id = CronUtil.schedule("*/2 * * * * *", (Runnable) () -> Console.log("task running : 2s"));
final String id = CronUtil.schedule("*/2 * * * * *", (Runnable) () -> Console.log("task running : 2s"));
Console.log(id);
CronUtil.remove(id);

View File

@@ -5,7 +5,7 @@ import cn.hutool.cron.CronUtil;
import cn.hutool.cron.task.InvokeTask;
public class DeamonMainTest {
public static void main(String[] args) {
public static void main(final String[] args) {
// 测试守护线程是否对作业线程有效
CronUtil.schedule("*/2 * * * * *", new InvokeTask("cn.hutool.cron.demo.TestJob.doWhileTest"));
// 当为守护线程时stop方法调用后doWhileTest里的循环输出将终止表示作业线程正常结束

View File

@@ -7,7 +7,7 @@ import cn.hutool.cron.CronUtil;
*/
public class JobMainTest {
public static void main(String[] args) {
public static void main(final String[] args) {
CronUtil.setMatchSecond(true);
CronUtil.start(false);
}

View File

@@ -28,7 +28,7 @@ public class TestJob {
*/
@SuppressWarnings("InfiniteLoopStatement")
public void doWhileTest() {
String name = Thread.currentThread().getName();
final String name = Thread.currentThread().getName();
while (true) {
Console.log("Job {} while running...", name);
ThreadUtil.sleep(2000);

View File

@@ -25,7 +25,7 @@ public class CronPatternBuilderTest {
@Test
public void buildRangeTest(){
String build = CronPatternBuilder.of()
final String build = CronPatternBuilder.of()
.set(Part.SECOND, "*")
.setRange(Part.HOUR, 2, 9)
.build();
@@ -34,7 +34,7 @@ public class CronPatternBuilderTest {
@Test(expected = CronException.class)
public void buildRangeErrorTest(){
String build = CronPatternBuilder.of()
final String build = CronPatternBuilder.of()
.set(Part.SECOND, "*")
// 55无效值
.setRange(Part.HOUR, 2, 55)

View File

@@ -49,7 +49,7 @@ public class CronPatternNextMatchTest {
@Test
public void nextMatchAfterTest(){
CronPattern pattern = new CronPattern("23 12 * 12 * * *");
final CronPattern pattern = new CronPattern("23 12 * 12 * * *");
// 时间正常递增
//noinspection ConstantConditions
@@ -90,7 +90,7 @@ public class CronPatternNextMatchTest {
@Test
public void nextMatchAfterByWeekTest(){
CronPattern pattern = new CronPattern("1 1 1 * * Sat *");
final CronPattern pattern = new CronPattern("1 1 1 * * Sat *");
// 周日下个周六在4月9日
final DateTime time = DateUtil.parse("2022-04-03");
assert time != null;

View File

@@ -14,7 +14,7 @@ public class CronPatternTest {
@Test
public void matchAllTest() {
CronPattern pattern;
final CronPattern pattern;
// 任何时间匹配
pattern = CronPattern.of("* * * * * *");
assertMatch(pattern, DateUtil.formatNow());
@@ -24,7 +24,7 @@ public class CronPatternTest {
public void matchAllTest2() {
// 在5位表达式中秒部分并不是任意匹配而是一个固定值0
// 因此此处匹配就不能匹配秒
CronPattern pattern;
final CronPattern pattern;
// 任何时间匹配
// 分 时 天 月 周
pattern = CronPattern.of("* * * * *");
@@ -125,7 +125,7 @@ public class CronPatternTest {
@Test
public void patternNegativeTest() {
// -4表示倒数的数字此处在小时上-4表示 23 - 4为19
CronPattern pattern = CronPattern.of("* 0 -4 * * ?");
final CronPattern pattern = CronPattern.of("* 0 -4 * * ?");
assertMatch(pattern, "2017-02-09 19:00:00");
assertMatch(pattern, "2017-02-19 19:00:33");
}
@@ -172,7 +172,7 @@ public class CronPatternTest {
* @param date 日期,标准日期时间字符串
*/
@SuppressWarnings("ConstantConditions")
private void assertMatch(CronPattern pattern, String date) {
private void assertMatch(final CronPattern pattern, final String date) {
Assert.assertTrue(pattern.match(DateUtil.parse(date).toCalendar(), false));
Assert.assertTrue(pattern.match(DateUtil.parse(date).toCalendar(), true));
}

View File

@@ -12,7 +12,7 @@ public class CronPatternUtilTest {
@Test
public void matchedDatesTest() {
//测试每30秒执行
List<Date> matchedDates = CronPatternUtil.matchedDates("0/30 * 8-18 * * ?", DateUtil.parse("2018-10-15 14:33:22"), 5, true);
final List<Date> matchedDates = CronPatternUtil.matchedDates("0/30 * 8-18 * * ?", DateUtil.parse("2018-10-15 14:33:22"), 5, true);
Assert.assertEquals(5, matchedDates.size());
Assert.assertEquals("2018-10-15 14:33:30", matchedDates.get(0).toString());
Assert.assertEquals("2018-10-15 14:34:00", matchedDates.get(1).toString());
@@ -24,7 +24,7 @@ public class CronPatternUtilTest {
@Test
public void matchedDatesTest2() {
//测试每小时执行
List<Date> matchedDates = CronPatternUtil.matchedDates("0 0 */1 * * *", DateUtil.parse("2018-10-15 14:33:22"), 5, true);
final List<Date> matchedDates = CronPatternUtil.matchedDates("0 0 */1 * * *", DateUtil.parse("2018-10-15 14:33:22"), 5, true);
Assert.assertEquals(5, matchedDates.size());
Assert.assertEquals("2018-10-15 15:00:00", matchedDates.get(0).toString());
Assert.assertEquals("2018-10-15 16:00:00", matchedDates.get(1).toString());
@@ -36,7 +36,7 @@ public class CronPatternUtilTest {
@Test
public void matchedDatesTest3() {
//测试最后一天
List<Date> matchedDates = CronPatternUtil.matchedDates("0 0 */1 L * *", DateUtil.parse("2018-10-30 23:33:22"), 5, true);
final List<Date> matchedDates = CronPatternUtil.matchedDates("0 0 */1 L * *", DateUtil.parse("2018-10-30 23:33:22"), 5, true);
Assert.assertEquals(5, matchedDates.size());
Assert.assertEquals("2018-10-31 00:00:00", matchedDates.get(0).toString());
Assert.assertEquals("2018-10-31 01:00:00", matchedDates.get(1).toString());

View File

@@ -8,7 +8,7 @@
# cn.hutool.cron.demo.TestJob.doTest = */1 * * * * *
[cn.hutool.cron.demo]
[cn.hutool.cron.demo]=
# 6位表达式在秒匹配模式下可用此处表示每秒执行一次
# TestJob.doTest = */1 * * * * *
# 5位表达式在分匹配模式下可用此处表示每分钟执行一次