简体   繁体   English

在运行时将数据保存在服务器中的首选方法是什么

[英]what are the preferred ways to persist data in server in runtime

I have a web application which has the UI having its requests handles by Struts Action class. 我有一个Web应用程序,其UI具有Struts Action类的请求句柄。

Lets say that the UI sends data for 30 variables at a single request. 假设UI在单个请求中发送30个变量的数据。 The action class process the request and stores the 30 variables in a java object. action类处理请求并将30个变量存储在java对象中。

I need to persist the data beyond the request scope (even after the server sends response back to client for that request received, the data has to be persisted), because i have another servlet which relies on this persisted data (those 30 variables updated through UI). 我需要将数据保留在请求范围之外(即使在服务器将响应发送回客户端以获取该请求之后,数据也必须保留),因为我有另一个依赖于此持久数据的servlet(通过更新的那些30个变量) UI)。

Ways to persistence: 持久性的方法:

  1. Store it in DB 将其存储在DB中
  2. Use JPA 使用JPA
  3. Use static variables. 使用静态变量。
  4. Using MQ 使用MQ

Which among the above would you prefer? 您更喜欢上述哪一种? I guess the third option doesn't hold good. 我猜第三种选择并不好。

Added Points to have a better clarity: 添加点以获得更好的清晰度:

  • The UI sends a request (holds around 30 String variable data) for every 1 minute. UI每1分钟发送一个请求(保存大约30个String变量数据)。 For every one min, the persisted data has to be modified. 每隔一分钟,必须修改持久数据。

  • The another servlet which relies on this persisted data is no way 另一个依赖于这个持久化数据的servlet是没有办法的
    related to the request, hence i believe the session context will not be shared. 与请求相关,因此我认为会话上下文不会被共享。

Could you use an HttpSession ? 你能用HttpSession吗? You can put the data in a session, which keeps it stored on the server side, and then it's persisted across requests and available to other servlets. 您可以将数据放在会话中,使其保存在服务器端,然后将其保存在请求之间并可供其他servlet使用。

Not enough information. 信息不足。 It really depends on many different factors (what the app does, how much data, etc) which you haven't elaborated on. 这实际上取决于许多不同的因素(应用程序做了什么,有多少数据等),你还没有详细说明。 All of those approaches could be the correct one in a certain situation. 在某种情况下,所有这些方法都可能是正确的。 Even the static variable option could be right in some bizarre case. 在一些奇怪的情况下,即使是静态变量选项也是正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM