I have a Java servlet that retrieves data from a mysql database. To minimize callbacks to the database, it is retrieved only once in the init () method and placed in the HashMap <> (i.e., Cached in memory).
Now this HashMap is a member of the servlet class. I need to not only store this data, but also update some values (actually counters) in cached objects of the base class of hashmap values. And there is a Timer (or Cron task) to schedule the reset of these counters in the DB.
So, after googling, I found 3 options for storing cached data:
1), as now, as a member of the servlet class (but servlets can be decommissioned and returned to operation by the container at will, and then the data will be lost)
2) in ServletContext (is it true that it is recommended to store small amounts of data here?)
3) in the JNDI resource.
What is the most preferred way?
source share