Arian
Arian

Reputation: 7749

Where to keep in-memory data shared between users

In my spring boot app, I want to keep the number of users who subscribe to each websocket channel.

I'd like to do this using a concurrent hashmap, but I don't know where I should keep this data structure, so all users share it. From my understanding, putting it in a component doesn't lead to being "shared" between requests.

I have to mention that I never touched sessions in my app, as authentication is based on JWT.

Upvotes: 1

Views: 844

Answers (1)

Essex Boy
Essex Boy

Reputation: 7988

Create a Service/Bean which holds data in ehCache, good example here

I would not use a Map.

Based on Arian Hosseinzadeh below which I think is correct. Just create a normal @Service Bean, it will be a singleton by default.

Upvotes: 1

Related Questions