`
xiaoZ5919
  • 浏览: 401415 次
  • 性别: Icon_minigender_1
  • 来自: 安平人@北京
博客专栏
Group-logo
Netty学习笔记
浏览量:72864
社区版块
存档分类
最新评论

Spring异步任务@asynch

阅读更多

AOP+JCU的ThreadPool和Future实现了异步任务,很简单,直接看spring实现的源代码吧:

public Object invoke(final MethodInvocation invocation) throws Throwable {
		Future result = this.asyncExecutor.submit(new Callable<Object>() {
			public Object call() throws Exception {
				try {
					Object result = invocation.proceed();
					if (result instanceof Future) {
						return ((Future) result).get();
					}
				}
				catch (Throwable ex) {
					ReflectionUtils.rethrowException(ex);
				}
				return null;
			}
		});
		if (Future.class.isAssignableFrom(invocation.getMethod().getReturnType())) {
			return result;
		}
		else {
			return null;
		}
	}
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics