springmvc异步处理
好久没有写过博客了,都是看大牛的文章,略过~~
突然感觉成长在于总结!废话不多说,开干
由于是公司项目,所以不方便给出代码,看图操作

在项目util目录下创建工具类TaskExecutorConfig 并且实现 org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
该工具类用@EnableAsync修饰,表示可以用于异步;并且要实现
getAsyncExecutor()方法和
getAsyncUncaughtExceptionHandler()方法;在
getAsyncExecutor()内创建线程池并返回调用;

在需要异步调用的地方创建异步类TaskExecutorConfig并调用它的getAsyncExecutor()方法,得到线程池java.util.concurrent.
Executor对象;再通过Executor.execute(new MyRunnable(mapParam))实现异步;MyRunnable是我创建的内部类
public static class MyRunnable implements Runnable {
private Map<String,Object> mapParam;
public MyRunnable(Map<String,Object> mapParam){
this.mapParam = mapParam;
}
/**
* 重写run方法
*/
@Override
public void run() {
concertVideo(mapParam);
}
}
需要注意的是Executor在java.util.concurrent中;
如果这样不行可以再试试用@ComponentScan("com.videoadmin.async")修饰异步类TaskExecutorConfig;再通过以下方式实现异步:
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TaskExecutorConfig.class);
TaskService taskService = context.getBean(TaskService.class);
taskService.doAsync(destFile,objectId);
// 这里调用异步方法...
context.close();
@Service
public class TaskService {
private static String piantouTs = "F:\\shiping_test\\tsFile\\test\\2.ts";
@Async
public String doAsync(String filePath,String objectId) throws Exception {
if (filePath != null) {
filePath = ConvertVideo.transTOts(filePath);
if (filePath != null) {
filePath = ConvertVideo.concatVideo(piantouTs, filePath);
if (filePath != null) {
filePath = ConvertVideo.processMp4(filePath);
if (filePath != null) {
return filePath;
}
}
}
}
return null;
}
}
springmvc异步处理的更多相关文章
- SpringMVC异步调用,Callable和DeferredResult的使用
Callable和DeferredResult都是springMVC里面的异步调用,Callable主要用来处理一些简单的逻辑,DeferredResult主要用于处理一些复杂逻辑 1.Callabl ...
- SpringBoot+springmvc异步处理请求
有两种情况,第一种是业务逻辑复杂,但不需要业务逻辑的结果,第二种是需要返回业务逻辑的处理结果 第一种比较简单,利用多线程处理业务逻辑,或者利用spring中@Asyn注解更简单, 使用@Asyn注解, ...
- 天天写同步,5种SpringMvc异步请求了解下!
引言 说到异步大家肯定首先会先想到同步.我们先来看看什么是同步? 所谓同步,就是发出一个功能调用时,在没有得到结果之前,该调用就不返回或继续执行后续操作. 简单来说,同步就是必须一件一件事做,等前一件 ...
- Springmvc异步上传文件
<script src="js/jquery.js" type="text/javascript"></script><scrip ...
- SpringMVC异步文件上传下载
首先了解一下File的构造方法: File(String pathname):根据一个路径得到File对象 File(String parent,String child):根据一个目录和一个子文件/ ...
- SpringMVC 异步与定时使用示例
1.Spring 的xml配置: <aop:aspectj-autoproxy/> <task:annotation-driven executor="annotation ...
- SpringMVC异步处理的 5 种方式
作者:丁仪 来源:https://chengxuzhixin.com/blog/post/SpringMVC-yi-bu-chu-li-de-5-zhong-fang-shi.html 前段时间研究了 ...
- springmvc异步上传图片并回调页面函数插入图片url代码示例
<tr> <td class="search_td">属性值图片值:</td> <td> <input type=" ...
- Springmvc 异步处理
package com.lookcoder.haircutmember.controller.login.page.async; import org.slf4j.Logger; import org ...
随机推荐
- 按行读取String类型
BufferedReader br = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(content.getByt ...
- 热度3年猛增20倍,Serverless&云开发的技术架构全解析
『 作为一个不断发展的新兴技术, Serverless 热度的制高点已然到来.』 或许,Google Trends 所显示的 3 年猛增 20 倍的" Serverless " 搜 ...
- 【Spring容器】项目启动后初始化数据的两种实践方案
早期业务紧急,没有过多的在意项目的运行效率,现在回过头看走查代码,发现后端项目(Spring MVC+MyBatis)在启动过程中多次解析mybatis的xml配置文件及初始化数据,对开发阶段开发人员 ...
- 20141126-DotNetStack
- JQuery学习笔记(3)——节点操作 节点查找
插入节点 内部插入 所谓的内部插入,就是指在节点里面的插入,而外部插入,则是在节点外面插入. append() prepend() appendTo() prependTo() append和prep ...
- 关于Calendar的一些用法总结
import java.util.Calendar; import java.security.KeyStore.TrustedCertificateEntry; import java.text.D ...
- kubernetes的volume的权限设置(属主和属组)
apiVersion: v1kind: Podmetadata: name: hello-worldspec: containers: # specification of the pod's c ...
- 解密Kafka吞吐量高的原因
众所周知kafka的吞吐量比一般的消息队列要高,号称the fastest,那他是如何做到的,让我们从以下几个方面分析一下原因. 生产者(写入数据) 生产者(producer)是负责向Kafka提交数 ...
- spark 源码分析之七--Spark RPC剖析之RpcEndPoint和RpcEndPointRef剖析
RpcEndpoint 文档对RpcEndpoint的解释:An end point for the RPC that defines what functions to trigger given ...
- thymeleaf常用属性
转 作者:ITPSC 出处:http://www.cnblogs.com/hjwublog/ th:action 定义后台控制器路径,类似<form>标签的action属性. 例如: ...