mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -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");
|
||||
|
@@ -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);
|
||||
|
@@ -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里的循环输出将终止,表示作业线程正常结束
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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);
|
||||
|
@@ -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)
|
||||
|
@@ -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;
|
||||
|
@@ -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));
|
||||
}
|
||||
|
@@ -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());
|
||||
|
@@ -8,7 +8,7 @@
|
||||
|
||||
# cn.hutool.cron.demo.TestJob.doTest = */1 * * * * *
|
||||
|
||||
[cn.hutool.cron.demo]
|
||||
[cn.hutool.cron.demo]=
|
||||
# 6位表达式在秒匹配模式下可用,此处表示每秒执行一次
|
||||
# TestJob.doTest = */1 * * * * *
|
||||
# 5位表达式在分匹配模式下可用,此处表示每分钟执行一次
|
||||
|
Reference in New Issue
Block a user