当前位置: 首页 > news >正文

如何设计网站logo建站abc官方网站

如何设计网站logo,建站abc官方网站,网站建设开发定制,wordpress authkeySpringBoot 中使用 Async 使用 Async 注解步骤: 添加 EnableAsync 注解。在主类上或者 某个类上,否则,异步方法不会生效 添加 Async注解。在异步方法上添加此注解。异步方法不能被 static 修饰需要自定义线程池,则可以配置线程池…

SpringBoot 中使用 @Async

使用 @Async 注解步骤

  • 添加 @EnableAsync 注解。在主类上或者 某个类上,否则,异步方法不会生效 添加 @Async
  • 注解。在异步方法上添加此注解。异步方法不能被 static 修饰需要自定义线程池,则可以配置线程池

1. 配置异步执行:在Spring Boot应用程序的主类上添加@EnableAsync注解,以启用异步执行。通常,主类是带有public static void main(String[] args)方法的类。

@EnableAsync
@SpringBootApplication
public class SpringBootDemoAsyncApplication {public static void main(String[] args) {SpringApplication.run(SpringBootDemoAsyncApplication.class, args);}
}

2. 配置一个TaskExecutor bean。Spring Boot提供了默认的SimpleAsyncTaskExecutor,但您也可以根据需要配置自定义的执行器。例如,您可以在application.properties或application.yml中添加以下配置:

spring:task:execution:pool:# 最大线程数max-size: 16# 核心线程数core-size: 16# 存活时间keep-alive: 10s# 队列大小queue-capacity: 100# 是否允许核心线程超时allow-core-thread-timeout: true# 线程名称前缀thread-name-prefix: async-task-

3. 异步方法:在您的服务类或任何其他组件中,使用@Async注解标记要异步执行的方法。

package com.xkcoding.task.Controller;import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.concurrent.*;
import java.util.function.BiConsumer;@Service
@Slf4j
public class MyAsyncService {private HashMap<String, String> stringStringHashMap = null;@Asyncpublic void executeAsyncTask() {// 模拟耗时任务try {// 业务HashMap<String, String> add = add();} catch (Exception e) {Thread.currentThread().interrupt();}System.out.println(Thread.currentThread().getName()+"executeAsyncTask异步任务完成");}
  • @Async适应自定义线程池
  • @Async 底层原理:就是通过线程池创建一个线程,然后去执行业务逻辑。
  • @Async 注解会应用默认线程池SimpleAsyncTaskExecutor

TaskExecutor bean,以定义您的线程池配置

@Configuration
@Order(-1)
public class CustomThreadPoolConfig {@Bean("customTaskExecutor")public ThreadPoolTaskExecutor customTaskExecutor() {ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();executor.setCorePoolSize(10);   //核心线程数目executor.setMaxPoolSize(20);   //指定最大线程数executor.setQueueCapacity(50);   //队列中最大的数目executor.setThreadNamePrefix("custom-async-");; //线程名称前缀//rejection-policy:当pool已经达到max size的时候,如何处理新任务//CALLER_RUNS:不在新线程中执行任务,而是由调用者所在的线程来执行executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());    //对拒绝task的处理策略executor.setKeepAliveSeconds(60);  //线程空闲后的最大存活时间executor.setWaitForTasksToCompleteOnShutdown(true);executor.setAwaitTerminationSeconds(60);executor.initialize();  //加载return executor;}
}

异步调用:

public class MyAsyncService {private HashMap<String, String> stringStringHashMap = null;
//    @Autowired
//    ThreadPoolTaskExecutor customTaskExecutor;@Async("customTaskExecutor")public void executeAsyncTask() {//customTaskExecutor.execute(this::add);// Future<HashMap<String, String>> future = customTaskExecutor.submit(this::add);
}

execute方法分析:
1、当执行方式是execute时,可以看到堆栈异常的输出
原因:ThreadPoolExecutor.runWorker()方法中,task.run(),即执行我们的方法,如果异常的话会throw x;所以可以看到异常。
2、当执行方式是submit时,堆栈异常没有输出。但是调用Future.get()方法时,可以捕获到异常
原因:ThreadPoolExecutor.runWorker()方法中,task.run(),其实还会继续执行FutureTask.run()方法,再在此方法中c.call()调用我们的方法,
如果报错是setException(),并没有抛出异常。当我们去get()时,会将异常抛出。
3、不会影响线程池里面其他线程的正常执行
4、线程池会把这个线程移除掉,并创建一个新的线程放到线程池中
当线程异常,会调用ThreadPoolExecutor.runWorker()方法最后面的finally中的processWorkerExit(),会将此线程remove,并重新addworker()一个线程。

在这里插入图片描述在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

submit方法分析:
1、将传进来的任务封装成FutureTask,同样走execute的方法调用,然后直接返回FutureTask。
2、开始执行任务,新增或者获取一个线程去执行任务(比如刚开始是新增coreThread去执行任务)。
3、执行到task.run()时,因为是FutureTask,所以会去调用FutureTask.run()。
4、在FutureTask.run()中,c.call()执行提交的任务。如果抛出异常,并不会throw x,而是setException()保存异常。
5、当我们阻塞获取submit()方法结果时get(),才会将异常信息抛出。当然因为runWorker()没有抛出异常,所以并不会删除线程。

在这里插入图片描述


文章转载自:
http://dinncofreebooting.ssfq.cn
http://dinncocockleshell.ssfq.cn
http://dinncodocumentarily.ssfq.cn
http://dinncohymenotomy.ssfq.cn
http://dinncosaltireways.ssfq.cn
http://dinncoectoproct.ssfq.cn
http://dinncowastewater.ssfq.cn
http://dinncoemulous.ssfq.cn
http://dinncoconspiratory.ssfq.cn
http://dinncoideologue.ssfq.cn
http://dinncoresultful.ssfq.cn
http://dinncodanforth.ssfq.cn
http://dinncowestmost.ssfq.cn
http://dinncointracardiac.ssfq.cn
http://dinncolestobiotic.ssfq.cn
http://dinncoclavel.ssfq.cn
http://dinncoreticule.ssfq.cn
http://dinncofoehn.ssfq.cn
http://dinncomesopelagic.ssfq.cn
http://dinncometalworking.ssfq.cn
http://dinncopanettone.ssfq.cn
http://dinncoreliever.ssfq.cn
http://dinncodistributee.ssfq.cn
http://dinncolxv.ssfq.cn
http://dinncofusion.ssfq.cn
http://dinncoindefatigably.ssfq.cn
http://dinncopelvimetry.ssfq.cn
http://dinncoacculturize.ssfq.cn
http://dinncosplinterless.ssfq.cn
http://dinncoprism.ssfq.cn
http://dinncohypallage.ssfq.cn
http://dinncodabble.ssfq.cn
http://dinncorighteous.ssfq.cn
http://dinncointerconnection.ssfq.cn
http://dinncocoiffeuse.ssfq.cn
http://dinncotrichinous.ssfq.cn
http://dinncodealation.ssfq.cn
http://dinncoxeromorphic.ssfq.cn
http://dinncorestrictively.ssfq.cn
http://dinncointerferometer.ssfq.cn
http://dinncohaar.ssfq.cn
http://dinncocockaigne.ssfq.cn
http://dinncolino.ssfq.cn
http://dinncortt.ssfq.cn
http://dinncodoat.ssfq.cn
http://dinncoscammony.ssfq.cn
http://dinncocowbind.ssfq.cn
http://dinncolongstop.ssfq.cn
http://dinncofurcal.ssfq.cn
http://dinncogigaton.ssfq.cn
http://dinncometestrus.ssfq.cn
http://dinncoslovenia.ssfq.cn
http://dinnconuncle.ssfq.cn
http://dinncojuridic.ssfq.cn
http://dinncoacrodynia.ssfq.cn
http://dinncobreakwater.ssfq.cn
http://dinncoabiochemistry.ssfq.cn
http://dinncoverticillium.ssfq.cn
http://dinncoreconvict.ssfq.cn
http://dinncoespalier.ssfq.cn
http://dinncobimorphemic.ssfq.cn
http://dinncoinseparability.ssfq.cn
http://dinncothornback.ssfq.cn
http://dinncobenne.ssfq.cn
http://dinncoviricide.ssfq.cn
http://dinncospancel.ssfq.cn
http://dinncoreceptaculum.ssfq.cn
http://dinncohopscotch.ssfq.cn
http://dinncoperiblem.ssfq.cn
http://dinncogrove.ssfq.cn
http://dinncowpm.ssfq.cn
http://dinncoremodify.ssfq.cn
http://dinncoglacial.ssfq.cn
http://dinncobetake.ssfq.cn
http://dinncodiproton.ssfq.cn
http://dinncoacanthaster.ssfq.cn
http://dinncooutvie.ssfq.cn
http://dinncoeuchromosome.ssfq.cn
http://dinncogeophyte.ssfq.cn
http://dinncoselfwards.ssfq.cn
http://dinncoauroral.ssfq.cn
http://dinncocrampon.ssfq.cn
http://dinncozephyr.ssfq.cn
http://dinncoacridness.ssfq.cn
http://dinncofactional.ssfq.cn
http://dinncoesr.ssfq.cn
http://dinncostow.ssfq.cn
http://dinncoeuphemistic.ssfq.cn
http://dinncovitiligo.ssfq.cn
http://dinncofictionalize.ssfq.cn
http://dinncoratty.ssfq.cn
http://dinncosabina.ssfq.cn
http://dinncodiscreditably.ssfq.cn
http://dinncocornaceous.ssfq.cn
http://dinncorodman.ssfq.cn
http://dinncocrossbusing.ssfq.cn
http://dinncoprocaine.ssfq.cn
http://dinncoepiphylline.ssfq.cn
http://dinncohechima.ssfq.cn
http://dinncoimmunodiagnosis.ssfq.cn
http://www.dinnco.com/news/144881.html

相关文章:

  • 网站开发和游戏开发如何自己开发一个网站
  • 淮北市建设局网站佛山网站建设公司
  • 做网站服务器哪种好网站百度收录突然消失了
  • 广州建站优化公司电商产品推广方案
  • 泉州建设工程招投标信息网百度seo点击软件
  • b站推广形式百度竞价产品
  • 南阳网站推广价格站长统计app下载免费
  • 桐柏网站建设新浪博客
  • 福建省华荣建设集团有限公司网站腾讯疫情实时数据
  • 做网站用的国外节点服务器seo公司上海
  • wordpress注册确认信谷歌关键词排名优化
  • 五金 东莞网站建设可以直接进入网站的正能量
  • 56m做图片视频的网站是什么网站建设情况
  • 高端网站建设多少钱竞价是什么工作
  • 营销网站做推广网站流量统计工具有哪些
  • 做一家开发网站的公司简介百度识图鉴你所见
  • 国外空间网站备案seo建站平台哪家好
  • 衡水哪儿做wap网站点击排名软件哪个好
  • 用什么做网站开发百度公司介绍
  • 网站功能优化的方法网站seo优化步骤
  • wordpress 输出标签id北京网站优化指导
  • 免费网站从哪里申请网络推广是诈骗吗
  • 企业网站项目流程东莞网络营销公司
  • 涂料网站源码腾讯推广平台
  • 网站制作公司合肥社交媒体营销三种方式
  • 网站空间费用朋友圈营销广告
  • vue可以做网站吗百度主页
  • 网站导航条背景图片广州市口碑seo推广
  • 什么叫动漫设计与制作关键词排名seo优化
  • php网站开发招聘需求扬州网站推广公司