好久没有写过博客了,都是看大牛的文章,略过~~

突然感觉成长在于总结!废话不多说,开干

由于是公司项目,所以不方便给出代码,看图操作

在项目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异步处理的更多相关文章

  1. SpringMVC异步调用,Callable和DeferredResult的使用

    Callable和DeferredResult都是springMVC里面的异步调用,Callable主要用来处理一些简单的逻辑,DeferredResult主要用于处理一些复杂逻辑 1.Callabl ...

  2. SpringBoot+springmvc异步处理请求

    有两种情况,第一种是业务逻辑复杂,但不需要业务逻辑的结果,第二种是需要返回业务逻辑的处理结果 第一种比较简单,利用多线程处理业务逻辑,或者利用spring中@Asyn注解更简单, 使用@Asyn注解, ...

  3. 天天写同步,5种SpringMvc异步请求了解下!

    引言 说到异步大家肯定首先会先想到同步.我们先来看看什么是同步? 所谓同步,就是发出一个功能调用时,在没有得到结果之前,该调用就不返回或继续执行后续操作. 简单来说,同步就是必须一件一件事做,等前一件 ...

  4. Springmvc异步上传文件

    <script src="js/jquery.js" type="text/javascript"></script><scrip ...

  5. SpringMVC异步文件上传下载

    首先了解一下File的构造方法: File(String pathname):根据一个路径得到File对象 File(String parent,String child):根据一个目录和一个子文件/ ...

  6. SpringMVC 异步与定时使用示例

    1.Spring 的xml配置: <aop:aspectj-autoproxy/> <task:annotation-driven executor="annotation ...

  7. SpringMVC异步处理的 5 种方式

    作者:丁仪 来源:https://chengxuzhixin.com/blog/post/SpringMVC-yi-bu-chu-li-de-5-zhong-fang-shi.html 前段时间研究了 ...

  8. springmvc异步上传图片并回调页面函数插入图片url代码示例

    <tr> <td class="search_td">属性值图片值:</td> <td> <input type=" ...

  9. Springmvc 异步处理

    package com.lookcoder.haircutmember.controller.login.page.async; import org.slf4j.Logger; import org ...

随机推荐

  1. PTP 接线方式及通讯距离

    PTP 接线方式 CB 1241 RS485 接线 (6ES7 241 1CH30-1XB0) CB1241 RS485 信号板(安装在CPU机本体上) ,订货号为: 6ES7 241 1CH30-1 ...

  2. 20131222-Dom省市加载-第二十七天

    [1]省市选择 <head> <title></title> <script type="text/javascript"> win ...

  3. 学习2:内容# 1.while # 2.字符串格式化 # 3.运算符 # 4.编码初始

    目录 1.while循环 2.字符串格式化 3.运算符 4.编码初始 1.while循环 while -- 关键字 (死循环) if 条件: 结果 while 条件: 循环体 while True: ...

  4. MySQL5.7.20源码安装以及pt-query-digest用法示例

    MySQL5.7.20源码安装1.下载解压cd /data/app/mysql5.7wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5 ...

  5. 整型,布尔值,字符串详解,for语句 练习

    2019 年 7 月 8 日 1.将今天的课上的代码敲一遍,然后整理笔记 已完成 2.有变量name = "aleX leNb" 完成如下操作: 移除 name 变量对应的值两边的 ...

  6. 列表 元组 range

    2019 年 7 月 9 日 列表---list------容器 列表:存储数据,支持多个数据类型,比如 :字符串 数字 布尔值 列表 集合 元组 ​ 特点 : 有序 可变 支持索引 (定义一个列表不 ...

  7. [JavaWeb] Ubuntu下载eclipse for ee

    进入网站进行下载 https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/2019- ...

  8. C++小游戏——井字棋

    #include<cstdio> #include<windows.h> #include<ctime> int main() { srand(time(NULL) ...

  9. 你真的了解 Cookie 和 Session 吗

    我在做面试官的时候,曾经问过很多朋友这个问题: Cookie 和 Session 有什么区别呢?大部分的面试者应该都可以说上一两句,比如:什么是 Cookie?什么是 Session?两者的区别等. ...

  10. Go语言圣经习题练习_1.6并发获取多个URL

    练习 1.10: 找一个数据量比较大的网站,用本小节中的程序调研网站的缓存策略,对每个URL执行两遍请求,查看两次时间是否有较大的差别,并且每次获取到的响应内容是否一致,修改本节中的程序,将响应结果输 ...