应用程序的体系结构:请求处理

编程入门 行业动态 更新时间:2024-10-28 07:32:03
本文介绍了应用程序的体系结构:请求处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有以下问题:

我写使用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.

更多推荐

应用程序的体系结构:请求处理

本文发布于:2023-11-11 16:38:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578999.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:体系结构   应用程序

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!