java - Why use a database instead of singleton bean fields? -
java - Why use a database instead of singleton bean fields? -
my utilize case real-time spring mvc application deals little amount of non-critical info "churns" rapidly. info consists of around 20 key-value string pairs. pulled in on schedule external api, can modified end user interacting webapp, , used produce parameters in post external api on schedule.
this may obvious, perhaps obvious have reply can find anywhere, why maintain info in db opposed using dedicated singleton class thread-safe fields such concurrenthashmap, injected @services need it? initial feeling class such allow quicker read/writes in-memory db, yet every illustration have seen relies on "proper" db:
@repository public class datastore{ private map info = new concurrenthashmap<string, string>(); //...getters , setters etc.. } thanks thoughts!
you can utilize concurrentmap store key/value pairs in memory, nil wrong it. "proper" db provides persistence, info still there when restart application. db provides atomicity, map on own not (however can added simple locking).
java spring-mvc persistence
Comments
Post a Comment