Storing game state in sprin boot in memory [closed]

1 week ago 15
ARTICLE AD BOX

I created a mutable game state and I'd like to have a map which maps a game id to the object, but I have pretty much no experience doing so (aka building a statefull spring boot application) and have troubles finding a good solution with some explanation on to how properly store and utilize the game states. I'd appreciate any and all source material you can provide, or some example if possible

Pavlo Shevchyk's user avatar

7

Are you just looking to store data in a database? Something else? It's not clear what you're attempting or what specifically has you stuck.

2026-04-21 14:38:16 +00:00

Commented 17 hours ago

I'd imagine that there is no reason to store it in an actual database, as there is supposed to be only one game server to utilize a single game state. Is there a way to store some form of HashMap such that it 1. Avoids raising conditions 2. Is not destroyed while the server is running The difficulty mostly arises from my lack of knowledge about how Spring Boot manages the instances of classes and how it works with threads.

2026-04-21 14:44:38 +00:00

Commented 17 hours ago

Maybe an "in memory database", such as H2 or maybe Redis? Either one should have tutorials and examples to get started. If you want even simpler than that as you imply, what happens if you simply store your data in a static value somewhere? Do you run into any problems when testing it?

2026-04-21 14:49:00 +00:00

Commented 17 hours ago

Storing in a variable is my plane, its just that I'd avoid using weird solutions for the project, as it is kind of part of my bachelor thesis and I'd be interested in how it is usually done. Issue is, there is not much of info on that on the web as id like, or I am just missing it.

2026-04-21 14:51:57 +00:00

Commented 17 hours ago

It's not really clear what info you're looking for then. If you want to store a value in a variable (or, more specifically, a static value on a class) then what stops you? As for "how it is usually done" that would likely be an in-memory database for temporary/volatile data or a persisted database for long-term storage.

2026-04-21 14:56:25 +00:00

Commented 17 hours ago

Read Entire Article