diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 39ab141..6bacd93 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -21,6 +21,11 @@
+
+
+
+
+
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index f259f61..130dc96 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,15 +5,12 @@
+
+
-
+
-
-
-
-
-
@@ -177,6 +174,7 @@
+
diff --git a/CompletableFuture.txt b/CompletableFuture.txt
new file mode 100644
index 0000000..5b910f3
--- /dev/null
+++ b/CompletableFuture.txt
@@ -0,0 +1,119 @@
+https://blog.51cto.com/u_16297326/13571760
+
+总结:
+
+CompletableFuture 是 Java 中实现异步编程的强大工具,它提供了丰富的 API 来创建、组合和处理异步任务,
+能够帮助开发者构建高性能、高响应性的应用程序。通过本文的详细介绍和代码示例,
+读者应该对 CompletableFuture 的基本使用、链式调用、组合多个任务、异常处理以及实际应用等方面有了深入的了解。
+在实际开发中,灵活运用 CompletableFuture 的特性,结合性能优化和最佳实践,能够有效提升应用程序的性能和用户体验。
+随着 Java 技术的不断发展和应用场景的日益复杂,掌握 CompletableFuture 等异步编程技术对于 Java 开发者来说显得尤为重要。
+
+
+
+七、实际应用案例:构建复杂的异步工作流
+为了更好地理解 CompletableFuture 的实际应用,我们来看一个构建复杂异步工作流的案例。
+假设我们需要开发一个电商订单处理系统,其中包含多个异步任务,如验证用户信息、检查库存、计算运费、处理支付等。
+这些任务之间存在一定的依赖关系,需要合理地组合和处理。
+
+
+// 验证用户信息
+CompletableFuture validateUserAsync(String userId) {
+ return CompletableFuture.supplyAsync(() -> {
+ System.out.println("Validating user...");
+ // 模拟网络延迟
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ // 返回用户对象
+ return new User(userId);
+ });
+}
+
+// 检查库存
+CompletableFuture checkInventoryAsync(Product product, int quantity) {
+ return CompletableFuture.supplyAsync(() -> {
+ System.out.println("Checking inventory for product: " + product.getId());
+ // 模拟网络延迟
+ try {
+ Thread.sleep(1500);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ // 返回是否有足够库存
+ return product.getStock() >= quantity;
+ });
+}
+
+// 计算运费
+CompletableFuture calculateShippingCostAsync(User user, double totalWeight) {
+ return CompletableFuture.supplyAsync(() -> {
+ System.out.println("Calculating shipping cost...");
+ // 模拟网络延迟
+ try {
+ Thread.sleep(1200);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ // 根据用户地址和总重量计算运费
+ return totalWeight * 0.5;
+ });
+}
+
+// 处理支付
+CompletableFuture processPaymentAsync(User user, double amount) {
+ return CompletableFuture.supplyAsync(() -> {
+ System.out.println("Processing payment...");
+ // 模拟网络延迟
+ try {
+ Thread.sleep(1800);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+ // 返回支付是否成功
+ return true;
+ });
+}
+
+// 构建订单处理工作流
+public void processOrder(String userId, Product product, int quantity) {
+ // 验证用户信息
+ CompletableFuture userFuture = validateUserAsync(userId);
+
+ // 检查库存
+ CompletableFuture inventoryFuture = userFuture
+ .thenCompose(user -> checkInventoryAsync(product, quantity));
+
+ // 计算运费
+ CompletableFuture shippingCostFuture = inventoryFuture
+ .thenCompose(hasInventory -> {
+ if (hasInventory) {
+ return calculateShippingCostAsync(userFuture.join(), product.getWeight() * quantity);
+ } else {
+ return CompletableFuture.completedFuture(0.0);
+ }
+ });
+
+ // 处理支付
+ CompletableFuture paymentFuture = shippingCostFuture
+ .thenCompose(shippingCost -> {
+ double totalAmount = product.getPrice() * quantity + shippingCost;
+ return processPaymentAsync(userFuture.join(), totalAmount);
+ });
+
+ // 最终处理
+ paymentFuture
+ .thenAccept(paymentSuccess -> {
+ if (paymentSuccess) {
+ System.out.println("Order processed successfully.");
+ } else {
+ System.out.println("Payment failed, order not processed.");
+ }
+ })
+ .exceptionally(ex -> {
+ System.out.println("Error occurred during order processing: " + ex.getMessage());
+ return null;
+ })
+ .join();
+}
\ No newline at end of file
diff --git a/README.md b/README.md
index b0d7bab..4e79797 100644
--- a/README.md
+++ b/README.md
@@ -3,6 +3,14 @@
java CompletableFuture异步回调:
https://blog.csdn.net/n0430/article/details/147880286
+https://juejin.cn/post/7487071171194945547
+
+https://blog.csdn.net/Linging_24/article/details/144832725
+
+https://blog.51cto.com/u_16297326/13571760
+
+
+
# Spring-axis
diff --git a/pom.xml b/pom.xml
index 0204878..fa6fdaf 100644
--- a/pom.xml
+++ b/pom.xml
@@ -268,10 +268,12 @@
+
- maven-public
- http://192.168.1.24:8081/repository/maven-public/
+ repository
+ http://47.242.184.139:8081/repository/maven-public/
true
diff --git a/src/main/java/com/rehome/mqttclienttemperature/controller/JdbcDemoController.java b/src/main/java/com/rehome/mqttclienttemperature/controller/JdbcDemoController.java
index ae2adef..6a84231 100644
--- a/src/main/java/com/rehome/mqttclienttemperature/controller/JdbcDemoController.java
+++ b/src/main/java/com/rehome/mqttclienttemperature/controller/JdbcDemoController.java
@@ -10,6 +10,8 @@ import com.rehome.mqttclienttemperature.entity.Temperature;
import com.rehome.mqttclienttemperature.service.TemperatureService;
import com.rehome.mqttclienttemperature.utils.JdbcUtil;
import lombok.extern.slf4j.Slf4j;
+import org.apache.http.util.TextUtils;
+import org.attoparser.util.TextUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -90,6 +92,10 @@ public class JdbcDemoController {
@RequestMapping("/api/list")
public ResponseDto queryList() {
+ // 自定义一个线程池,内部包含8个线程
+ ExecutorService customPool = Executors.newFixedThreadPool(8);
+ // 自定义一个线程池,内部包含10个线程
+ ExecutorService executorService = Executors.newFixedThreadPool(10);
CompletableFuture future = CompletableFuture.supplyAsync(() -> {
String sql = "select * from temperature where id = ?";
List