springmvc非同期処理

 

ブログを書いていない長い時間は、スキップ、ダニエルの記事を参照することです~~

突然感が要約することを増加しました!騒ぎ、ドライオープン

このプロジェクトは、コード、プラグインの操作与えられたので、便利ではない会社であるため、

プロジェクトと実現org.springframework.aop.interceptor.AsyncUncaughtExceptionHandlerでTaskExecutorConfigのutilディレクトリのツールを作成します。

修飾@EnableAsync使用されるツールは、非同期表現するために使用することができ、そして達成します

getAsyncExecutor()メソッド、及び
getAsyncUncaughtExceptionHandler()メソッドは、中
スレッドプールgetAsyncExecutorを(作成)と内のコールを返します。

非同期クラスTaskExecutorConfig必要な非同期呼び出しを作成し、スレッドプールjava.util.concurrentのを取得するためにgetAsyncExecutor()メソッドを呼び出します。

その後、とてexecutor.execute(新しい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;
}
}

 

おすすめ

転載: www.cnblogs.com/sjyBlog/p/11348758.html