应用程序的体系结构:请求处理 [英] Architecture of the application: request processing

查看:172
本文介绍了应用程序的体系结构:请求处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:

我写使用servlet和JSP的Web应用程序,应查询单独的服务。
但查询需要大量的时间 - 大约30秒。

I am writing a web application with servlets and JSP which should query a separate service. But the query takes a lot of time - around 30 seconds.

我的应用程序的结构很简单 - 过滤器 - >控制器 - > JSP。我在想什么,而控制器进入上执行自己的工作,如果在过滤器中我将请求发送到一个单独的线程来处理。我拿什么为了使查询过程和控制器的处理同时做? + I需要查询每5分钟被更新(使得用户确实有相关的信息)。什么是做到这一点的最佳途径?

The structure of my app is simple - Filter->Controller->jsp. I was thinking what if in the filter I send the request into a separate thread to be processed while the controller goes on executing its job. What shall I do in order to make the querying process and controller processing simultaneous? + I need the query to be renewed every 5 mins (so that the user does have the relevant info). What is the optimum way to do that?

推荐答案

使用一个的ServletContextListener来启动一个线程,当Web应用程序启动。

Use a ServletContextListener to start a thread when the web application starts.

的线程应的数据写入ServletContext中(例如,经由的setAttribute())。

The thread should write the data into the ServletContext (e.g. via setAttribute()).

当应用程序已停止了ServletContextListener应终止线程。

The ServletContextListener should terminate the thread when the application is stopped.

该servlet应该从ServletContext中读取数据,因为它需要它。

The Servlet should read the data from the ServletContext as it needs it.

这篇关于应用程序的体系结构:请求处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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