应用架构:请求处理 [英] Architecture of the application: request processing

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

问题描述

我有以下问题:

我正在编写一个带有 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.我在想,如果在过滤器中我将请求发送到一个单独的线程中以在控制器继续执行其工作时进行处理会怎样.我应该怎么做才能使查询过程和控制器处理同时进行?+ 我需要每 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天全站免登陆