[ server ] [ scheduler ]- script scheduler accomplish - 2
This commit is contained in:
@@ -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;
|
||||
|
||||
76
server/src/test/java/io/wdd/server/SimpleTest.java
Normal file
76
server/src/test/java/io/wdd/server/SimpleTest.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user