修改:代码包路径

This commit is contained in:
lxyer 2020-05-04 10:36:39 +08:00
parent 2384f9f9e4
commit a759953dfa
10 changed files with 102 additions and 86 deletions

View File

@ -4,9 +4,9 @@
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>com.lxyer</groupId> <groupId>net.tccn</groupId>
<artifactId>redtimer</artifactId> <artifactId>redtimer</artifactId>
<version>0.1.0</version> <version>0.1.1</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<dependencies> <dependencies>
<dependency> <dependency>
@ -22,9 +22,10 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration> <configuration>
<source>1.8</source> <source>14</source>
<target>1.8</target> <target>14</target>
</configuration> </configuration>
</plugin> </plugin>
</plugins> </plugins>

View File

@ -1,7 +1,7 @@
package com.lxyer.timer; package net.tccn.timer;
import com.lxyer.timer.queue.TimerQueue; import net.tccn.timer.queue.TimerQueue;
import com.lxyer.timer.task.Task; import net.tccn.timer.task.Task;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;

View File

@ -1,8 +1,8 @@
package com.lxyer.timer; package net.tccn.timer;
import com.lxyer.timer.scheduled.Scheduled; import net.tccn.timer.scheduled.Scheduled;
import com.lxyer.timer.task.Job; import net.tccn.timer.task.Job;
import com.lxyer.timer.task.Task; import net.tccn.timer.task.Task;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneId; import java.time.ZoneId;

View File

@ -1,6 +1,6 @@
package com.lxyer.timer.queue; package net.tccn.timer.queue;
import com.lxyer.timer.task.Task; import net.tccn.timer.task.Task;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet; import java.util.HashSet;
@ -20,8 +20,8 @@ public class TimerQueue{
* @param task * @param task
*/ */
public void push(Task task) { public void push(Task task) {
remove(task.getName());
synchronized (lock){ synchronized (lock){
remove(task.getName());
int inx = size;//目标坐标 int inx = size;//目标坐标
while (inx > 0 && queue[inx-1].theTime() > task.theTime()){ while (inx > 0 && queue[inx-1].theTime() > task.theTime()){
inx--; inx--;

View File

@ -1,4 +1,4 @@
package com.lxyer.timer.scheduled; package net.tccn.timer.scheduled;
import java.time.LocalDateTime; import java.time.LocalDateTime;

View File

@ -1,4 +1,4 @@
package com.lxyer.timer.scheduled; package net.tccn.timer.scheduled;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;

View File

@ -1,9 +1,7 @@
package com.lxyer.timer.scheduled; package net.tccn.timer.scheduled;
import java.text.SimpleDateFormat;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;

View File

@ -1,4 +1,4 @@
package com.lxyer.timer.task; package net.tccn.timer.task;
/** /**
* @author: liangxianyou at 2018/12/8 17:24. * @author: liangxianyou at 2018/12/8 17:24.

View File

@ -1,7 +1,7 @@
package com.lxyer.timer.task; package net.tccn.timer.task;
import com.lxyer.timer.TimerExecutor; import net.tccn.timer.TimerExecutor;
import com.lxyer.timer.scheduled.Scheduled; import net.tccn.timer.scheduled.Scheduled;
/** /**
* @author: liangxianyou at 2018/8/5 19:32. * @author: liangxianyou at 2018/8/5 19:32.

View File

@ -1,8 +1,9 @@
package com.lxyer.timer; package net.tccn.timer;
import com.lxyer.timer.scheduled.ScheduledCycle; import net.tccn.timer.scheduled.Scheduled;
import com.lxyer.timer.scheduled.ScheduledExpres; import net.tccn.timer.scheduled.ScheduledCycle;
import com.lxyer.timer.task.Task; import net.tccn.timer.scheduled.ScheduledExpres;
import net.tccn.timer.task.Task;
import org.junit.Test; import org.junit.Test;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -41,8 +42,6 @@ public class TimerTest {
}*/ }*/
Thread.sleep(5000); Thread.sleep(5000);
} }
@ -70,11 +69,7 @@ public class TimerTest {
if ("*".equals(minute)) {//* if ("*".equals(minute)) {//*
next = start.plusMinutes(1); next = start.plusMinutes(1);
} else if (minute.matches("^[0-5]??[0-9]??$")) {//n } else if (minute.matches("^[0-5]??[0-9]??$")) {//n
next = LocalDateTime.of(start.getYear(), next = LocalDateTime.of(start.getYear(), start.getMonth(), start.getDayOfMonth(), start.getHour(), Integer.parseInt(minute));
start.getMonth(),
start.getDayOfMonth(),
start.getHour(),
Integer.parseInt(minute));
} else if (minute.matches("^[*]/[0-9]+$")) {// */5 } else if (minute.matches("^[*]/[0-9]+$")) {// */5
next = start.plusMinutes(Integer.parseInt(minute.replace("*/", ""))); next = start.plusMinutes(Integer.parseInt(minute.replace("*/", "")));
} else if (minute.matches("^([0-5]??[0-9]??,)+([0-5]??[0-9]??)? $")) {//1,3 } else if (minute.matches("^([0-5]??[0-9]??,)+([0-5]??[0-9]??)? $")) {//1,3
@ -85,11 +80,7 @@ public class TimerTest {
inx = i + 1; inx = i + 1;
} }
} }
next = LocalDateTime.of(start.getYear(), next = LocalDateTime.of(start.getYear(), start.getMonth(), start.getDayOfMonth(), start.getHour(), Integer.parseInt(minutes[inx]));
start.getMonth(),
start.getDayOfMonth(),
start.getHour(),
Integer.parseInt(minutes[inx]));
} else if (minute.matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??$")) {//1-3 } else if (minute.matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??$")) {//1-3
int m = start.getMinute(); int m = start.getMinute();
String[] split = minute.split("-"); String[] split = minute.split("-");
@ -116,7 +107,7 @@ public class TimerTest {
/** /**
* 测试各种正则表达式的合法性 * 测试各种正则表达式的合法性
*/ */
//@Test @Test
public void t4() { public void t4() {
//Pattern pattern = Pattern.compile(); //Pattern pattern = Pattern.compile();
//Minute * 1,3 1-3 */5 3-15/5 //Minute * 1,3 1-3 */5 3-15/5
@ -127,51 +118,51 @@ public class TimerTest {
//System.out.println("1-3".matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??$")); //System.out.println("1-3".matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??$"));
//System.out.println("3-18/5".matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??/[0-5]??[0-9]??$")); //System.out.println("3-18/5".matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??/[0-5]??[0-9]??$"));
String str = "01-05/5";// * 1,3 1-3 */5 3-15/5 //String str = "01-05/5";// * 1,3 1-3 */5 3-15/5
System.out.println(str.matches("^[0-5]??[0-9]??$")); //System.out.println(str.matches("^[0-5]??[0-9]??$"));
System.out.println(str.matches("^[*]/[0-9]+$")); //System.out.println(str.matches("^[*]/[0-9]+$"));
System.out.println(str.matches("^([0-5]??[0-9]??,)+([0-5]??[0-9]??)?$")); //System.out.println(str.matches("^([0-5]??[0-9]??,)+([0-5]??[0-9]??)?$"));
System.out.println(str.matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??$")); //System.out.println(str.matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??$"));
System.out.println(str.matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??/[0-5]??[0-9]??$")); //System.out.println(str.matches("^[0-5]??[0-9]??\\-[0-5]??[0-9]??/[0-5]??[0-9]??$"));
System.out.println("111".matches("^[0-9]+.*[0-9]+$"));
} }
/** /**
* 测试配置的表达式 * 测试配置的表达式
*/ */
//@Test @Test
public void t6() { public void t6() {
// //
TimerExecutor executor = new TimerExecutor(10); TimerExecutor timer = new TimerExecutor(3);
/* /*
08 18 * 7,8 4 08 18 * 7,8 4
"task1", "1 22-23 * * 7" "task1", "1 22-23 * * 7"
*/ */
Task task = TimerTask.by("task1", ScheduledExpres.of("1 22-23 * * 7"), (t) -> { /*Task task = TimerTask.by("task1", ScheduledExpres.of("16-24 0-2 * * *"), t -> {
//System.out.println("");
System.out.println("----"); System.out.println("----");
//System.out.println(new SimpleDateFormat("0: yyyy-MM-dd HH:mm:ss").format(theTime()));
//System.out.println(new SimpleDateFormat("1: yyyy-MM-dd HH:mm:ss").format(nextTime()));
/*System.out.println(new SimpleDateFormat("2: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("3: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("4: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("5: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("6: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("7: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("8: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("9: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("10: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("11: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("12: yyyy-MM-dd HH:mm:ss").format(nextTime()));
System.out.println(new SimpleDateFormat("13: yyyy-MM-dd HH:mm:ss").format(nextTime()));*/
}); });
timer.add(task);*/
timer.add(TimerTask.by("task2", ScheduledCycle.of("5s"), t -> {
System.out.println("task2 运行了。。。");
t.setScheduled(ScheduledCycle.of("15s"));
t.setComplete(true);
}));
timer.remove("task2");
/*
task.run(); task.run();
task.setScheduled(ScheduledCycle.of(1000 * 5));//定时每秒执行 task.setScheduled(ScheduledCycle.of(1000 * 5));//定时每秒执行
task.run(); task.run();*/
try {
Thread.sleep(1000 * 60 * 60);
} catch (InterruptedException e) {
e.printStackTrace();
}
} }
@ -197,4 +188,30 @@ public class TimerTest {
e.printStackTrace(); e.printStackTrace();
} }
} }
//@Test
public void t8() {
String str = "1M";
System.out.println();
Scheduled scheduled = null;
if (str.matches("^\\d+[y,M,d,H,m,s]$")) {
String endchar = str.substring(str.length() - 1);
long period = Long.parseLong(str.substring(0, str.length() - 1));
if ("y".equals(endchar)) scheduled = ScheduledCycle.of(period * 1000 * 60 * 60 * 24 * 365);
else if ("M".equals(endchar)) scheduled = ScheduledCycle.of(period * 1000 * 60 * 60 * 24 * 30);
else if ("d".equals(endchar)) scheduled = ScheduledCycle.of(period * 1000 * 60 * 60 * 24);
else if ("H".equals(endchar)) scheduled = ScheduledCycle.of(period * 1000 * 60 * 60);
else if ("m".equals(endchar)) scheduled = ScheduledCycle.of(period * 1000 * 60);
else if ("s".equals(endchar)) scheduled = ScheduledCycle.of(period * 1000);
else scheduled = ScheduledCycle.of(period);
} else {
scheduled = ScheduledExpres.of(str);
}
}
} }