Situation
I have several servlets with one responsibility that take a request, do their job, respond and execute โ in these cases, you donโt need to maintain state.
However, I have a โPlain old Java objectโ that maintains status information based on the actions that the user initiated on the client that I would like to make available to my servlets on request. I would like to make a single instance of this object available and don't need / don't want to support multiple shared instances.
Side note: this data is temporary (you need to save it for 10 minutes) and not quite what I would like to save in the database.
Question
I supported a shared instance of an object with JSP before, but in this case the servlet makes more sense. So my question is, how can I appropriately manage the lifetime of this stateful object and can share it between servlets without saving by HTTP requests or some other mechanism?
In other words, if it is a non-web application, servlets without state preservation will be objects to which I would delegate the task, and stateful objects will support the results.
I looked at the ServletContext, but I do not quite understand the purpose of this, to know if I need it.
bn. source share