Java多线程开发中的Springboot 中异步请求方法的使用

SpringBoot 八种实现异步的方法 异步的八种实现方式 阅读详情

在过往的后台开发中,我们往往使用java自带的线程或线程池,来进行异步的调用。这对于效果来说没什么,甚至可以让开发人员对底层的状况更清晰,但是对于代码的易读性和可维护性却非常的差。

开发人员在实际使用过程中,应该更多的将精力放置在业务代码的书写过程中,而不是系统代码的维护中。你需要懂,但是不需要你直接维护去写,这才是编程语言的风向标。(这也是为什么spring在目前的java开发中,占用比重如此之大的原因之一)

下面来看使用Springboot 来实现异步调用的集中场景

一、简易注解,无需额外配置

1、添加@EnableAsync 到启动类(或者线程池配置类中)

2、添加@Async到需要异步执行的方法中

代码如下:

启动类

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;">1 @EnableAsync
2 @SpringBootApplication
3 public class DemoLearnSpringbootApplication {
4 
5     public static void main(String[] args) {
6         SpringApplication.run(DemoLearnSpringbootApplication.class, args);
7     }
8 }

调用类

<pre class="prettyprint hljs less" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Component
 2 public class SimpleAsyncDemo {
 3     @Autowired
 4     private SimpleTaskHandler simpleTaskHandler;
 5 
 6 
 7     @PostConstruct
 8     public void execTaskHandler1() {
 9         try {
10             simpleTaskHandler.handle1(2);
11             simpleTaskHandler.handle2(2);
12             simpleTaskHandler.handle3(2);
13             simpleTaskHandler.handle1(2);
14             simpleTaskHandler.handle2(2);
15             simpleTaskHandler.handle3(2);
16             simpleTaskHandler.handle1(2);
17             simpleTaskHandler.handle2(2);
18             simpleTaskHandler.handle3(2);
19         } catch (InterruptedException e) {
20             e.printStackTrace();
21         }
22     }
23   
24 }

被异步调用的类

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Component
 2 public class SimpleTaskHandler {
 3 
 4     public void printCurrentTime(String key) {
 5         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 6         System.out.println(format.format(new Date()) + "***" + key + "****" + Thread.currentThread().getName());
 7     }
 8 
 9     @Async
10     public void handle1(int time) throws InterruptedException {
11         TimeUnit.SECONDS.sleep(time);
12         printCurrentTime("handle1");
13     }
14 
15     @Async
16     public void handle2(int time) throws InterruptedException {
17         TimeUnit.SECONDS.sleep(time);
18         printCurrentTime("handle2");
19     }
20 
21     @Async
22     public void handle3(int time) throws InterruptedException {
23         TimeUnit.SECONDS.sleep(time);
24         printCurrentTime("handle3");
25     }
26 
27 
28 }

执行结果

handle1、handle2、handle3的执行结果为乱序,不可预估。这样最简易的通过2个注解即完成异步线程的调用了。

细心的同学已经发现了,连续调用9次异步线程后,最后一次的线程名称就会与之前的重复。这是由于默认的线程池配置的结果。

默认配置如下

<pre class="prettyprint hljs gradle" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"># 核心线程数
spring.task.execution.pool.core-size=8  
# 最大线程数
spring.task.execution.pool.max-size=16
# 空闲线程存活时间
spring.task.execution.pool.keep-alive=60s
# 是否允许核心线程超时
spring.task.execution.pool.allow-core-thread-timeout=true
# 线程队列数量
spring.task.execution.pool.queue-capacity=100
# 线程关闭等待
spring.task.execution.shutdown.await-termination=false
spring.task.execution.shutdown.await-termination-period=
# 线程名称前缀
spring.task.execution.thread-name-prefix=task-

二、自定义线程池

只通过注解来完成异步线程调用,简单明了,对应的异步线程来自springboot 默认生成的异步线程池。但是有些场景却并不满足。所以我们需要针对业务需要定义自己的线程池配置文件

1、在application.properties中定义我们自己的线程池配置

2、在springboot项目中,添加对应的线程池bean对象

3、添加@EnableAsync 到启动类(或者线程池配置类中)

4、添加@Async到需要异步执行的方法中

代码如下:

application.properties配置文件

<pre class="prettyprint hljs verilog" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;">task.pool.demo.corePoolSize= 5
task.pool.demo.maxPoolSize= 10
task.pool.demo.keepAliveSeconds= 300
task.pool.demo.queueCapacity= 50

调用类

<pre class="prettyprint hljs less" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Component
 2 public class SimpleAsyncDemo {
 3 
 4     @Autowired
 5     private PoolTaskHandler poolTaskHandler;
 6 
 7 
 8     @PostConstruct
 9     public void execTaskHandler2() {
10         try {
11             poolTaskHandler.handle1(2);
12             poolTaskHandler.handle2(2);
13             poolTaskHandler.handle3(2);
14             poolTaskHandler.handle1(2);
15             poolTaskHandler.handle2(2);
16             poolTaskHandler.handle3(2);
17             poolTaskHandler.handle1(2);
18             poolTaskHandler.handle2(2);
19             poolTaskHandler.handle3(2);
20         } catch (InterruptedException e) {
21             e.printStackTrace();
22         }
23     }
24 
25 }

异步线程池的配置类

<pre class="prettyprint hljs kotlin" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Configuration
 2 public class ThreadPoolConfig {
 3 
 4     @Value("${task.pool.demo.corePoolSize}")
 5     private int corePoolSize;
 6     @Value("${task.pool.demo.maxPoolSize}")
 7     private int maxPoolSize;
 8     @Value("${task.pool.demo.queueCapacity}")
 9     private int queueCapacity;
10     @Value("${task.pool.demo.keepAliveSeconds}")
11     private int keepAliveSeconds;
12 
13 
14     @Bean("handleAsync")
15     public TaskExecutor taskExecutor() {
16         ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
17         // 设置核心线程数
18         executor.setCorePoolSize(corePoolSize);
19         // 设置最大线程数
20         executor.setMaxPoolSize(maxPoolSize);
21         // 设置队列容量
22         executor.setQueueCapacity(queueCapacity);
23         // 设置线程活跃时间(秒)
24         executor.setKeepAliveSeconds(keepAliveSeconds);
25         // 设置默认线程名称前缀
26         executor.setThreadNamePrefix("Thread-ABC-");
27         // 设置拒绝策略
28         executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
29         // 等待所有任务结束后再关闭线程池
30         executor.setWaitForTasksToCompleteOnShutdown(true);
31         return executor;
32     }
33 }

被异步调用的类

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Component
 2 public class PoolTaskHandler {
 3 
 4     public void printCurrentTime(String key) {
 5         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 6         System.out.println(format.format(new Date()) + "***" + key + "****" + Thread.currentThread().getName());
 7     }
 8 
 9     @Async("handleAsync")
10     public void handle1(int time) throws InterruptedException {
11         TimeUnit.SECONDS.sleep(time);
12         printCurrentTime("handle-1");
13     }
14 
15     @Async("handleAsync")
16     public void handle2(int time) throws InterruptedException {
17         TimeUnit.SECONDS.sleep(time);
18         printCurrentTime("handle-2");
19     }
20 
21     @Async("handleAsync")
22     public void handle3(int time) throws InterruptedException {
23         TimeUnit.SECONDS.sleep(time);
24         printCurrentTime("handle-3");
25     }
26 
27 
28 }

执行结果如下

与上例类似,我们发现请求线程变成了每5个一批,这与我们在配置文件中的配置互相印证

调用类

<pre class="prettyprint hljs dart" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Component
 2 public class SimpleAsyncDemo {
 3 
 4     @Autowired
 5     private ReturnTaskHandler returnTaskHandler;
 6 
 7     @PostConstruct
 8     public void execTaskHandler3() {
 9         try {
10             String a1 = returnTaskHandler.handle1(2);
11             String a2 = returnTaskHandler.handle2(2);
12             String a3 = returnTaskHandler.handle3(2);
13             String a4 = returnTaskHandler.handle1(2);
14             String a5 = returnTaskHandler.handle2(2);
15             String a6 = returnTaskHandler.handle3(2);
16             String a7 = returnTaskHandler.handle1(2);
17             String a8 = returnTaskHandler.handle2(2);
18             String a9 = returnTaskHandler.handle3(2);
19             int c = 1;
20         } catch (InterruptedException e) {
21             e.printStackTrace();
22         }
23     }
24 
25 }

被调用类

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Component
 2 public class ReturnTaskHandler {
 3 
 4     public void printCurrentTime(String key) {
 5         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 6         System.out.println(format.format(new Date()) + "***" + key + "****" + Thread.currentThread().getName());
 7     }
 8 
 9     @Async("handleAsync")
10     public String handle1(int time) throws InterruptedException {
11         TimeUnit.SECONDS.sleep(time);
12         printCurrentTime("handle-1");
13         return "result1";
14     }
15 
16     @Async("handleAsync")
17     public String handle2(int time) throws InterruptedException {
18         TimeUnit.SECONDS.sleep(time);
19         printCurrentTime("handle-2");
20         return "result2";
21     }
22 
23     @Async("handleAsync")
24     public String handle3(int time) throws InterruptedException {
25         TimeUnit.SECONDS.sleep(time);
26         printCurrentTime("handle-3");
27         return "result3";
28     }
29 
30 }

其余代码继续我们使用上文中的其他代码

结果如下

所有结果返回都是null值。

如果想要拿到正确的执行结果,我们需要使用future接口类看来帮忙接住异步线程的返回结果(关于future等接口类的内容我会在后边的文章中讲解)

其余代码继续我们使用上文中的其他代码,改动的代码如下:

被调用类

<pre class="prettyprint hljs java" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Component
 2 public class ReturnSuccTaskHandler {
 3 
 4     public void printCurrentTime(String key) {
 5         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
 6         System.out.println(format.format(new Date()) + "***" + key + "****" + Thread.currentThread().getName());
 7     }
 8 
 9     @Async("handleAsync")
10     public Future<String> handle1(int time) throws InterruptedException {
11         TimeUnit.SECONDS.sleep(time);
12         printCurrentTime("handle-1");
13         return new AsyncResult<>("result1");
14     }
15 
16     @Async("handleAsync")
17     public Future<String> handle2(int time) throws InterruptedException {
18         TimeUnit.SECONDS.sleep(time);
19         printCurrentTime("handle-2");
20         return new AsyncResult<>("result2");
21     }
22 
23     @Async("handleAsync")
24     public Future<String> handle3(int time) throws InterruptedException {
25         TimeUnit.SECONDS.sleep(time);
26         printCurrentTime("handle-3");
27         return new AsyncResult<>("result3");
28     }
29 
30 
31 }

调用类

<pre class="prettyprint hljs kotlin" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto;"> 1 @Component
 2 public class SimpleAsyncDemo {
 3 
 4 
 5     @Autowired
 6     private ReturnSuccTaskHandler returnSuccTaskHandler;
 7 
 8 
 9 
10     @PostConstruct
11     public void execTaskHandler4() {
12         try {
13             Future<String> a1 = returnSuccTaskHandler.handle1(2);
14             Future<String> a2 = returnSuccTaskHandler.handle2(2);
15             Future<String> a3 = returnSuccTaskHandler.handle3(2);
16             Future<String> a4 = returnSuccTaskHandler.handle1(2);
17             Future<String> a5 = returnSuccTaskHandler.handle2(2);
18             Future<String> a6 = returnSuccTaskHandler.handle3(2);
19             Future<String> a7 = returnSuccTaskHandler.handle1(2);
20             Future<String> a8 = returnSuccTaskHandler.handle2(2);
21             Future<String> a9 = returnSuccTaskHandler.handle3(2);
22             while (true){
23                 // 如果任务都做完就执行如下逻辑
24                 if (a1.isDone() &&
25                         a2.isDone()&&
26                         a3.isDone()&&
27                         a4.isDone()&&
28                         a5.isDone()&&
29                         a6.isDone()&&
30                         a7.isDone()&&
31                         a8.isDone()&&
32                         a9.isDone()){
33                     SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
34                     System.out.println(format.format(new Date()) + "async task end.");
35                     System.out.println("async result:"+a1.get());
36                     System.out.println("async result:"+a2.get());
37                     System.out.println("async result:"+a3.get());
38                     System.out.println("async result:"+a3.get());
39                     System.out.println("async result:"+a4.get());
40                     System.out.println("async result:"+a5.get());
41                     System.out.println("async result:"+a6.get());
42                     System.out.println("async result:"+a7.get());
43                     System.out.println("async result:"+a8.get());
44                     System.out.println("async result:"+a9.get());
45                     break;
46                 }
47             }
48         } catch (InterruptedException | ExecutionException e) {
49             e.printStackTrace();
50         }
51     }
52 
53 
54 }

输出结果如下,我们可以发现 ,1、可以拿到返回结果,2、在最后一个子任务执行完成后,即立刻拿到结果。

Spring Boot异步请求处理框架 ​ 在Spring Boot项目中,经常会遇到处理时间过长,导致出现HTTP请求超时问题,状态码:502。​ 例如一个文件导入接口需要导入一个Excel文件的学员记录,原来是针对一个班的学员,最多500条记录,1分钟的HTTP超时时长之内基本可以响应。现在将很多班级的学员混在一起,放在一个Excel文件中(这样可以提高操作人员的工作效率),比如5万条学员记录,于是就出现HTTP请求超时问题。​ ​解决方案有:1)Ajax异步请求方式;2)WebSocket方式;3)异步请求处理方式:请求+轮询。 阅读详情

相关推荐

配置@Async异步任务的线程池

上一篇我们介绍了如何使用@Async注解来创建异步任务,我可以用这种方法来实现一些并发操作,以加速任务的执行效率。但是,如果只是如前文那样直接简单的创建来使用,可能还是会碰到一些问题。存在有什么问题呢?先来思考下,下面的这个接口,通过异步任务加速执行的实现,是否存在问题或风险呢? @RestController public class HelloController { @Autowired private AsyncTasks asyncTasks; @G

q1472750149的博客 1351

java中的异步请求

线程池 多线程

qq_44718662的博客 2472

Java多线程开发系列之五:Springboot 中异步请求方法的使用

开发人员在实际使用过程中,应该更多的将精力放置在业务代码的书写过程中,而不是系统代码的维护中。在过往的后台开发中,我们往往使用java自带的线程或线程池,来进行异步的调用。只通过注解来完成异步线程调用,简单明了,对应的异步线程来自springboot 默认生成的异步线程池。如果想要拿到正确的执行结果,我们需要使用future接口类看来帮忙接住异步线程的返回结果(关于future等接口类的内容我会在后边的文章中讲解)细心的同学已经发现了,连续调用9次异步线程后,最后一次的线程名称就会与之前的重复。...

lt_xiaodou的博客 226

SpringBoot 8种异步实现方式

什么是异步?在同步操作中,执行到发送短信的时候,我们必须等待这个方法彻底执行完才能执行赠送积分这个操作,如果赠送积分这个动作执行时间较长,发送短信需要等待,这就是典型的同步场景。实际上,发送短信和赠送积分没有任何的依赖关系,通过异步,我们可以实现赠送积分和发送短信这两个操作能够同时进行,比如:这就是所谓的异步,是不是非常简单,下面就说说异步的几种实现方式吧。/**

qq_21305943的专栏 6610

【Java】SpringBoot中使用ThreadPoolTaskExecutor实现异步多线程

一、配置类 @Configuration public class TaskConfig { @Bean("taskModuleExecutor") public ThreadPoolTaskExecutor taskExecutor() { ThreadPoolTaskExecutor threadPoolTaskExecutor = new ThreadPoolT...

Mr_EvanChen的Blog 3829

Springboot中开启多线程,实现异步非阻塞、异步阻塞、有无返回值的场景

开启多线程异步的方式有很多种,不单单局限以上方式,感兴趣的可以自行研究测试下,比如还可以使用来开启多线程,然后分别使用对应的execute()和submit()方法实现无返回值和有返回值的效果;以上内容均为个人理解,如存在不当欢迎提出改进。

weixin_45151960的博客 4092

Java多线程开发系列之Springboot 中异步请求方法的使用

在过往的后台开发中,我们往往使用java自带的线程或线程池,来进行异步的调用。这对于效果来说没什么,甚至可以让开发人员对底层的状况更清晰,但是对于代码的易读性和可维护性却非常的差...

guanshengg的博客 2118

SpringBoot多线程在项目中的实际应用

1、项目中实际运用---批量执行异步任务 2、批量异步查询-CompletableFuture的使用 2.1 几种创建方式 2.2 线程执行完成后走的方法 2.3 线程执行结果转换 2.3.1 thenApply 2.3.2 thenCompose 2.4 线程执行结果消费 2.4.1 thenAccept 2.4.2 thenAcceptBoth 2.4.3 thenRun 2.5 线程执行结果组合 3、项目中实际运用---多线程批量查询 4、SpringBoot中使用多线程

张刚的博客 1349

SpringBoot使用多线程

一、概述 1、为什么使用多线程 在我们开发系统过程中,经常会处理一些好费时间的任务(如:向数据库中插入上百万数据,将会导致系统等待),这个时候就会自然想到使用多线程。 2、为什么使用Spring来实现多线程 使用Spring比使用JDK原生的并发API更简单。(@Async就能解决)。 一般的开发环境都会集成Spring框架,Bean也都交给Spring来管理,因此,Spring实现多线程更简单。 3、为什么需要使用异步 传统的调用方式:调用一个服务,需要等待服务调用完成后,才能执行后面的代码,

csdn_life18的博客 3万+

【SpringBoot深入浅出系列】SpringBoot之多线程

多线程编程是提升 Spring Boot 应用性能和响应速度的重要手段。通过本文的介绍,我们了解了多线程的基本概念、Spring Boot 中的多线程应用场景、实现方式以及常见问题的解决方案。在实际开发中,我们需要根据具体的业务需求和场景,合理运用多线程技术,以实现高效、稳定的应用程序。希望本文能为读者在 Spring Boot 多线程编程方面提供有益的参考和帮助,让大家能够更好地掌握和应用这一强大的技术。

邓邓子的博客 1609

使用SAM进行遥感图像语义分割

SAM(Segment Anything Model)的成功表明了以数据为中心的机器学习的重要性。然而,由于遥感(RS)图像注释的困难和高成本,大量有价值的RS数据仍然没有被标记,特别是在像素级。在这项研究中,我们利用SAM和现有的RS物体检测数据集,开发了一个高效的管道来生成大规模的RS分割数据集,称为SAMRS。SAMRS在规模上超过了现有的高分辨率RS分割数据集几个数量级,并提供了物体类别、位置和实例信息,可用于语义分割、实例分割和物体检测,无论是单独还是组合。

lalula的博客 7456

SpringBoot开启异步多线程

SpringBoot 的异步多线程需要从 java 的多线程基础说起,可以参考java 多线程实现的三种方式区别。SpringBoot 在此基础上进行了多次封装,所以使用起来非常方便。

清泉影月 6353

美亚杯取证比赛必备:Veracrypt挂载+检材解压保姆级教程(附常见错误排查)

本文提供美亚杯数字取证竞赛的Veracrypt挂载与检材解压保姆级教程。详细解析从分卷压缩包解压(密码格式为MeiyaCup+年份)到使用Veracrypt正确挂载加密容器的全流程,并附有常见错误排查与高级应急方案,帮助选手高效突破技术门槛,顺利进入取证分析阶段。

alice7model的博客 1087

springboot中多线程的使用

程序:是为完成特定任务,用某种语言编写的一组指令的集合,即指一段静态的代码,静态对象。进程:是程序的一次执行过程,或是正在运行的一个程序,是一个动态的过程,有它自身的产生,存在和消亡的过程。-------生命周期线程:进程可进一步细化为线程,是一个程序内部的一条执行路径。

qq_36996785的博客 3849

STM32H7串口DMA避坑指南:如何解决RT-Thread默认驱动不支持的问题

本文针对STM32H7在RT-Thread系统中启用串口DMA时遇到的驱动不支持问题,提供了详细的解决方案。通过分析问题根源,指导修改驱动代码以适配H7的DMA Stream架构,并调整内存配置确保DMA可访问性,最终实现稳定高效的串口DMA通信。

weixin_29179311的博客 426

Blender点云渲染实战:用Geometry Nodes快速搞定论文配图(附Cycles渲染技巧)

本文详细介绍了如何利用Blender的Geometry Nodes系统,高效地将三维点云数据转化为高质量的科研论文配图。通过实战步骤,从数据导入、节点化几何处理、材质赋予到Cycles渲染引擎的优化设置,手把手教你制作出专业、美观的可视化图像,助力科研成果展示。

hp777的博客 273

JAVA SpringBoot 多线程配置、使用方法及注意事项

在Spring Boot中配置和使用多线程通常涉及以下几个方面:配置线程池、使用@Async注解、处理异步方法的返回值和异常、以及遵循最佳实践。

技术分享、程序员趣事、行业趋势等内容! 1650

32、社交媒体大数据中的情感分析与网络欺凌检测

本文探讨了社交媒体大数据在情感分析和网络欺凌检测中的应用。情感分析有助于应对自动化带来的社会变化、促进社会包容和推动环境保护。网络欺凌作为一种严重的在线危害,其检测依赖于数据预处理、特征提取与深度学习模型(如CNN、LSTM)进行分类。文章还总结了大数据在欺诈检测、医疗、制造、交通等领域的广泛应用,并分析了数据存储、处理速度、质量和技术工具等方面的挑战,提出了相应的应对策略。未来,随着技术进步,社交媒体大数据将在更多领域发挥关键作用。

cc789的博客 94

SpringBoot多线程进行异步请求的处理

近期在协会博客园中,有人发布了博客,系统进行查重的时候需要十秒左右时间才能处理完,由于一开始是单例模式,导致,在某人查重的时候整个系统是不会再响应别的请求的,导致了系统假死状态,那么我们就应该使用多线程进行处理,将这种不能快速返回结果的方法交给线程池进行处理。...

HumorChen的博客 3120

Qt C++ 电子海图与作战叠加(Overlay)系统

lab_pos->setText(QString("坐标: X%1 Y%2").arg(p.x(),0,'f',0).arg(p.y(),0,'f',0));lab_distance->setText(QString("距离: %1 海里").arg(dist,0,'f',1));lab_bearing->setText(QString("方位: %1°").arg(bear,0,'f',1));// 绘制S-57海图基底。scene->addText("封锁线").setPos(450,180);

寒寒豆豆软件公司的博客 503

【数据集】全球陆地表面反照率Albedo

【数据集】全球陆地表面反照率Albedo

WW、forever的博客 1457

springboot+多线程

在springboot的过程中,我们会使用到多线程去同时执行某个任务,那么我们就需要多线程,在以前的java中是自己去实现Thread或者runnable来实现多线程,springboot中已经自己拥有了多线程的注解@Async,那么我们现在使用这个注解来实现springboot的多线程 1.创建多线程的配置信息类: 在这个类中需要注解为@Configuration 及@Bean("XXX"),其中@Bean中的名称在我们日后使用@Async注解时需要制定的Bean类名,具体代码如下: pack.

jia.huang的博客 4148

三菱FX5U-PLC建立CClink的IO通讯

最新需要用三菱的FX5U的PLC搭建一个CClink通讯,PLC做主站,控制CClink从站的IO,下面2个输入模块AJ65SBTB1-32D,两个输出模块AJ65SBTB1-32T。3、在右侧的部件,选择网络模块:FX5-CCL-MS,CC-link主站模块。依次把加入两个AJ65SBTB1-32D,两个AJ65SBTB1-32T。7、基本设置,网络配置设置,链路刷新设置,设置好下面参数,应用。6、基本设置,网络配置设置,CC-Link配置设置。8、部件选择,模块,右键,添加模块标签。

wzz418550729的博客 1010

SpringBoot中使用多线程调用异步方法,异步方法有无返回值例子。

快速了解@Async注解的用法,包括异步方法无返回值、有返回值,最后总结@Async注解失效的几个坑。在我们的 SpringBoot 应用中,经常会遇到在一个接口中,同时做事情1,事情2,事情3,如果同步执行的话,则本次接口时间取决于事情1 2 3执行时间之和;如果三件事同时执行的话,那么本次接口的运行时间取决于事情1 2 3执行时间最长的那个。合理的使用多线程,可以大大缩短接口的运行时间。几个例子简单的介绍了一下多线程如何调用异步方法的例子。

L 756

C# WinForm 基于DirectShow.dll编写的程序,可边预览边保存视频,音频和图片

基于微软的DirectShow.dll的二次开发1.自动识别连接的摄像头跟麦克风且可以对其进行选择(默认选中第一个)2.可录制wmv和avi两种格式的视频并且都带有音频,avi可以录制的分辨率和帧数进行选择,wmv默认进行了淸晰度优化如不喜欢可去除代码中有相关提示3.可在预览点开之后进行拍照,也可边录制视频边拍照4.添加了视频和音频的压缩功能(酌情使用)这次二次开发发现C#对DirectShow的相关信息太少,这次做完也不敢藏私共享出来,还望大家指正

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

SpringBoot多线程

SpringBoot开启异步多线程_springboot 异步线程-CSDN博客这个就是推荐用法了在同一个类中,一个方法调用另外一个有注解(比如@Async,@Transational)的方法,注解失效的原因和解决方法_java async调用了两次-CSDN博客了解了失效的原因,解决的方法就简单了(两种):1.把这两个方法分开到不同的类中;2.把注解加到类名上面(这个类所有方法may都有注解的效果了..);

qq_52122048的博客 2846

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

上一篇: 怎样去优化JAVA中的实现代码
下一篇: Spring Security 自定义授权服务器实践
Java_ttcd
博客等级 码龄4年 198粉丝 190原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址