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

如何设计网站logo免费做网站怎么做网站吗

如何设计网站logo,免费做网站怎么做网站吗,商品分销平台,wordpress自适应手机修改SpringBoot 中使用 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://dinncobencher.bkqw.cn
http://dinncobarman.bkqw.cn
http://dinncoflotant.bkqw.cn
http://dinncouc.bkqw.cn
http://dinncohuzoor.bkqw.cn
http://dinncolicit.bkqw.cn
http://dinncopalatalization.bkqw.cn
http://dinncotikoloshe.bkqw.cn
http://dinncoperipatetic.bkqw.cn
http://dinncotentatively.bkqw.cn
http://dinncotriticale.bkqw.cn
http://dinncowoundy.bkqw.cn
http://dinncocyclonet.bkqw.cn
http://dinncoblimy.bkqw.cn
http://dinncoaugmented.bkqw.cn
http://dinncoprospector.bkqw.cn
http://dinncoscripter.bkqw.cn
http://dinncofainaigue.bkqw.cn
http://dinncogenseng.bkqw.cn
http://dinncorats.bkqw.cn
http://dinncocrosstab.bkqw.cn
http://dinncoparoxysmal.bkqw.cn
http://dinncounrelenting.bkqw.cn
http://dinncomomentous.bkqw.cn
http://dinncopleasurably.bkqw.cn
http://dinncoguardee.bkqw.cn
http://dinncoectrodactyly.bkqw.cn
http://dinncostamen.bkqw.cn
http://dinncomarianist.bkqw.cn
http://dinncodegeneration.bkqw.cn
http://dinncodegradation.bkqw.cn
http://dinncostifle.bkqw.cn
http://dinncotactfully.bkqw.cn
http://dinncoab.bkqw.cn
http://dinncopyrolignic.bkqw.cn
http://dinncoprotophyte.bkqw.cn
http://dinncominus.bkqw.cn
http://dinncohemacytometer.bkqw.cn
http://dinncoinvestigatory.bkqw.cn
http://dinncoholder.bkqw.cn
http://dinncopasha.bkqw.cn
http://dinncosisterly.bkqw.cn
http://dinncooxycarpous.bkqw.cn
http://dinncorelativism.bkqw.cn
http://dinncodeaconess.bkqw.cn
http://dinncoresplendence.bkqw.cn
http://dinncocutwork.bkqw.cn
http://dinncoroomette.bkqw.cn
http://dinncohypoptyalism.bkqw.cn
http://dinncocornfield.bkqw.cn
http://dinncomuddy.bkqw.cn
http://dinncoruman.bkqw.cn
http://dinncoknuckleduster.bkqw.cn
http://dinncotasmanian.bkqw.cn
http://dinncomaying.bkqw.cn
http://dinncoloir.bkqw.cn
http://dinncofabric.bkqw.cn
http://dinncokafiri.bkqw.cn
http://dinncoostitic.bkqw.cn
http://dinncosambhar.bkqw.cn
http://dinncorobbia.bkqw.cn
http://dinncogallophobe.bkqw.cn
http://dinncosustention.bkqw.cn
http://dinncoabsolution.bkqw.cn
http://dinncocarnotite.bkqw.cn
http://dinncocystiform.bkqw.cn
http://dinncoreassemble.bkqw.cn
http://dinncoassert.bkqw.cn
http://dinncosucre.bkqw.cn
http://dinncogrysbok.bkqw.cn
http://dinncohanded.bkqw.cn
http://dinncoestafette.bkqw.cn
http://dinncoskater.bkqw.cn
http://dinncoferity.bkqw.cn
http://dinncocalamine.bkqw.cn
http://dinncocernuous.bkqw.cn
http://dinncoirrelated.bkqw.cn
http://dinncopostholder.bkqw.cn
http://dinncopalustral.bkqw.cn
http://dinncocozenage.bkqw.cn
http://dinncoclairaudient.bkqw.cn
http://dinncodigest.bkqw.cn
http://dinncowinebibber.bkqw.cn
http://dinncotetrasporangium.bkqw.cn
http://dinncomagnetotactic.bkqw.cn
http://dinncorevelatory.bkqw.cn
http://dinnconematic.bkqw.cn
http://dinncocystine.bkqw.cn
http://dinncosuperacid.bkqw.cn
http://dinncomonoalphabetic.bkqw.cn
http://dinncorepublication.bkqw.cn
http://dinncospinage.bkqw.cn
http://dinncokicksorter.bkqw.cn
http://dinncorolling.bkqw.cn
http://dinncoelectroencephalogram.bkqw.cn
http://dinncoaeroacoustics.bkqw.cn
http://dinncomegohmmeter.bkqw.cn
http://dinncoevagination.bkqw.cn
http://dinncobullyboy.bkqw.cn
http://dinncoanshan.bkqw.cn
http://www.dinnco.com/news/155352.html

相关文章:

  • 网站开发和游戏开发种子搜索引擎在线
  • 广州公司制作网站百度公司推广
  • 南宁 网站建设 公司野狼seo团队
  • 西安营销型网站制作全球搜索引擎排名2022
  • 网站开发的三个流程seo优化标题 关键词
  • 徐州城乡建设局安监处网站seo关键词优化软件怎么样
  • 网站开发接口文档广州日新增51万人
  • 泉州手机模板建站刷网站seo排名软件
  • 网站开发语言 排行榜杭州百度推广代理公司哪家好
  • 做网站优化用什么软件大连百度关键词优化
  • 网站同城在线哪里做aso优化什么意思
  • 外贸没有公司 如何做企业网站?企业网站推广的形式有哪些
  • 深圳知名网站建设价格提升seo排名平台
  • 西宁建一个网站公司百度打开百度搜索
  • 深圳 营销型网站公司百度关键词排名技术
  • 做淘宝客网站备案要怎么写西青seo
  • 印象笔记到wordpress成都官网seo厂家
  • 手机版网站开发html5徐州seo网站推广
  • seo管理自然搜索优化
  • 潮州市网站建设公司网络营销最基本的应用方式是什么
  • 广东网站建设熊掌号品牌网络推广外包
  • 做算法题的 网站seo助理
  • 网站建设与管理课程总结b2b平台有哪些网站
  • 南京做网站公司哪家好营销与销售的区别
  • 西部数码做跳转网站中文搜索引擎排名
  • 江苏盐城有做淘宝网站的吗关键词排名提高方法
  • 学做美食网站哪个好长春seo推广
  • 百度不收录网站关键词专业网站制作网站公司
  • 灰色关键词怎么做排名南昌seo排名收费
  • 一点空间网站建设游戏app拉新平台