在Java中网络应用的异步任务 [英] Asynchronous Tasks in Java Web app

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

问题描述

异步工作,比如从网站下载的分数,或者一些重要的任务完成后发送电子邮件。
RightNow的我们,当我们下载了一些成绩,我们必须等待当前页面上获得响应页面或获取文件下载。
有没有办法,我可以点击下载分数可能性,它在后台发生的,这样我可以浏览到其他地区
网站,并在平均时间检查作业的状态。或者将来以后安排一些工作,并获得其执行结果
通过电子邮件。

Asynchronous jobs such as download scores from the website, or send emails after completion of some critical tasks. Rightnow we when we download some scores, we have to wait on the current page to get the response page or to get file downloaded. Is there a possibility that i can click on download scores and it happens in the background so that i can navigate to other parts of the website, and in the mean-time check the status of the job. Or Schedule some job later in the future and get its execution results via email.

我国是一个Struts 2 web应用与Hibernate 3.5 ORM。浏览到一些Java调度库后,得到了石英一些信息。
但是,石英上述规定或任何其他库,我可以尝试正确的库?
请指导我在正确的方向。

Ours is a struts 2 webapplication with Hibernate 3.5 ORM. After browsing into some java scheduling libraries, got some info on Quartz. But is Quartz the right library for the above requirements or any other library that i can try for? Please guide me in the right direction.

推荐答案

您将需要某种形式的异步处理的支持。您可以使用:

You will need some sort of asynchronous processing support. You can use:

  • quartz-scheduler - this library is very comprehensive and allows you to schedule all sorts of jobs. If you want to use it only for the purpose of scheduling jobs in the background and run them immediately, might be an overkill

使用线程池,请参阅<$c$c>Executors

use thread pool, see Executors class

JMS队列可以监听请求和异步处理他们 MDB 小号

jms queue can listen on requests and process them asynchronously in mdbs

最后,你可以利用 @Async / @Asynchronous 支持的春季或的 EJB

Finally you can take advantage of @Async/@Asynchronous support in spring or ejb

然后就莫名其妙地MUT恢复的结果。 Depening是否要直接在浏览器或通过电子邮件提供他们:

Then you mut somehow restore the results. Depening on whether you want to deliver them directly in the browser or via e-mail:


  • 每次你被渲染页面的时候,检查是否没有任何已完成/正在进行的作业。如果有一些已完成的作业,在页面上显示一个额外的链接某​​处(排序通知)。如果作业正在进行中,启动 AJAX请求并要求每隔一秒或使用长轮询/ 彗星立即接收结果

  • every time you are rendering a page, check whether there aren't any completed/in progress jobs. If there are some completed jobs, display an extra link on the page somewhere (sort of notification). If the job is in progress, start an ajax request and ask every other second or use long-polling/comet to receive the result immediately

如果您希望通过电子邮件发送的结果,只是在作业结束后发送。更简单但不太人性化恕我直言。

if you want to send results by e-mail, just send it after the job finishes. Much simpler but less user-friendly IMHO.

这篇关于在Java中网络应用的异步任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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