This commit is contained in:
APLS 2020-04-20 01:06:20 +08:00
parent 37e40bdcd8
commit 7aa57ae727
3 changed files with 58 additions and 0 deletions

View File

@ -56,6 +56,7 @@ public class TaskImpl implements ITask {
Outlook next = iterator.next(); Outlook next = iterator.next();
/*根据用户设置生成随机数*/ /*根据用户设置生成随机数*/
String Expiration = getRandom(next.getCronTimeRandomStart(), next.getCronTimeRandomEnd()); String Expiration = getRandom(next.getCronTimeRandomStart(), next.getCronTimeRandomEnd());
System.out.println("生成随机调用时间,github ID" + next.getGithubId() + ",时间:" + Expiration);
send(next.getGithubId(), Expiration); send(next.getGithubId(), Expiration);
} }
} }

View File

@ -0,0 +1,46 @@
package io.qyi.e5.string;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
/**
* @program: e5
* @description:
* @author: 落叶随风
* @create: 2020-04-20 00:38
**/
public class MyThread implements Runnable {
private Random random = null;
public MyThread() {
random = new Random();
}
@Override
public void run() {
try {
System.out.println("任务执行开始:" + new Date());
/**使用随机延时[0-3]秒来模拟执行任务*/
int sleepNumber = random.nextInt(3);
TimeUnit.SECONDS.sleep(2);
System.out.println("任务执行完毕:" + new Date());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
ScheduledThreadPoolExecutor service = new ScheduledThreadPoolExecutor(2);
System.out.println("开始任务");
for (int i = 0; i < 4; i++) {
//延时3秒执行
service.schedule(new MyThread(), 3, TimeUnit.SECONDS);
}
System.out.println("结束任务");
}
}

View File

@ -4,10 +4,15 @@ import com.google.gson.Gson;
import com.google.gson.JsonArray; import com.google.gson.JsonArray;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.Date;
import java.util.Iterator; import java.util.Iterator;
import java.util.Random; import java.util.Random;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
/** /**
* @program: e5 * @program: e5
@ -44,9 +49,15 @@ public class dome01 {
for (int i = 0; i < 30; i++) { for (int i = 0; i < 30; i++) {
System.out.println(getRandom(3600,7200)); System.out.println(getRandom(3600,7200));
} }
}
@Test
public void ScheduledExecutor(){
} }
public String getRandom(int start, int end){ public String getRandom(int start, int end){
Random r = new Random(); Random r = new Random();
String Expiration = String.valueOf((r.nextInt(end-start +1) + start) ); String Expiration = String.valueOf((r.nextInt(end-start +1) + start) );