• 社区居民
  • 忠实会员
  • 原创写手

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.

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.










喜欢0 评分0