Java EE中的异步执行 [英] Asynchronous execution in Java EE

查看:121
本文介绍了Java EE中的异步执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习Java EE(从SE移动),我对Java EE环境中的异步执行感到困惑。

基本上我理解创建线程定时器不是完全推荐的。到目前为止我发现的其他一种方法是使用JMS传输消息给EJB Message Bean,它将被异步执行。



有什么其他的方法来实现这个行为?使用JMS的原因看起来像简单任务的开销太多。

解决方案

Java EE 6中最简单的解决方案是使用 @Asynchronous 您的注释EJB方法(或整个类)。它允许您异步调用业务方法,这意味着将委派一个新线程来执行此方法,您将在调用者方法中获得控制权。



在Java EE前6天,JMS被用于此目的。



作为附注 - 在 Servlets 中,您还可以使用异步执行。


I'm learning Java EE currently (moving from SE) and I am confused about asynchronous execution in Java EE environment.
Basically what I understand creating Thread or Timer is not exactly recommended. One other method what I found so far are use JMS for transfer message to EJB Message Bean and it will be executed asynchronously.

What are some other methods to achieve this behavior? Cause using JMS looks like too much overhead for simple tasks.

解决方案

The simplest possible solution in Java EE 6 is to use @Asynchronous annotation on your EJB method (or the whole class). It allows you to invoke a business method asynchronously which means that a new thread will be delegated to execute this method and you'll get the control back in caller method.

In pre-Java EE 6 days the JMS was used for this purpose.

As a side note - in Servlets you can also use asynchronous execution.

这篇关于Java EE中的异步执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆