ECM
ECM
总版主
总版主
  • 社区居民
  • 忠实会员
  • 原创写手
阅读:700回复:0

Asynchronous Tasks in Java Web app

楼主#
更多 发布于:2016-05-16 10:53
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. 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.
answer(解决方案):

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 use thread pool, see Executors class jms queue can listen on requests and process them asynchronously in mdbs Finally you can take advantage of @Async/@Asynchronous support in spring or ejb Then you mut somehow restore the results. Depening on whether you want to deliver them directly in the browser or via e-mail: 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.

 

 

 

 

 

 

 

异常中心网是一家专门收集整理程序员编程过程中遇到的常见异常(exception)以及各种异常问答中心的网站。异常中心网旨在,减少程序员在编码遇到异常,处理各种异常时间和痛苦,让程序员能更愉快的、快速的定位异常并查找对应的异常解决方案。异常中心网诚心打造最完美的编程社区为程序员用户服务,努力成为最好的程序员乐园程序员社区程序异常中心程序bug中心异常问答中心

 

喜欢0 评分0
游客

返回顶部