Issue
I am trying to achieve a functionality to queue up a list of IDs or users that have connected to my application and dump it into the database every minute.
In order to achieve this I intend to store the IDs of said users in a set and then store the set in the database and empty the set every minute.
My challenge however includes
- how to use the same instance of the set across various requests from various users so that I can have a list of the various users.
I can't make use of sessions because As I mentioned above, the set is going to be IDs of different users using in different sessions.
Solution
You can use a class level variable in a @Service
, as it's default scope is singleton or a static variable. But you must maintain the content of the Set
properly, because it can lead to memory leak.
Answered By - zlaval