[ server ] [ scheduler ]- script scheduler accomplish - 2

This commit is contained in:
zeaslity
2023-02-01 13:59:56 +08:00
parent 07d7810087
commit 38c5a6a3c1
2 changed files with 77 additions and 2 deletions

View File

@@ -3,7 +3,6 @@ package io.wdd.rpc.scheduler.job;
import io.wdd.rpc.scheduler.beans.ScriptSchedulerDTO;
import io.wdd.rpc.scheduler.service.script.AgentApplyScheduledScript;
import io.wdd.server.beans.po.ScriptSchedulerPO;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

View File

@@ -0,0 +1,76 @@
package io.wdd.server;
import java.util.concurrent.CompletableFuture;
public class SimpleTest {
public static void main(String[] args) {
//任务1洗水壶->烧开水
CompletableFuture<String> f1 = CompletableFuture.supplyAsync(() -> {
try {
String name = Thread
.currentThread()
.getName();
System.out.println("name = " + name);
System.out.println("T1:洗水壶...");
Thread.sleep(1000);
System.out.println("T1:烧开水...");
Thread.sleep(15000);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "热水和水壶";
});
//任务2洗茶壶->洗茶杯->拿茶叶
CompletableFuture<String> f2 = CompletableFuture.supplyAsync(() -> {
try {
System.out.println("T2:洗茶壶...");
Thread.sleep(1000);
System.out.println("T2:洗茶杯...");
Thread.sleep(2000);
System.out.println("T2:拿茶叶...");
Thread.sleep(1000);
String name = Thread
.currentThread()
.getName();
System.out.println("name = " + name);
} catch (InterruptedException e) {
e.printStackTrace();
}
return "龙井";
});
//任务3任务1和任务2完成后执行泡茶
CompletableFuture<String> f3 = f1.thenCombine(
f2,
(result1, result2) -> {
System.out.println("result1 = " + result1);
System.out.println("result2 = " + result2);
System.out.println("T1:拿到茶叶:" + result2);
System.out.println("T1:泡茶...");
String currentAThreadName = Thread
.currentThread()
.getName();
System.out.println("currentAThreadName = " + currentAThreadName);
return "上茶:" + result2;
}
);
//等待任务3执行结果
System.out.println(f3.join());
String currentAThreadName = Thread
.currentThread()
.getName();
System.out.println("currentAThreadName = " + currentAThreadName);
}
}