Search code examples
jakarta-eeejbjboss7.xeardata-sharing

java sharing data in different apps with minimum hits to database


I'm having some functionality where i need to use data from database with minimum hits to database. This data is not changed frequently so I'm using static ConcurrentHashMap to load data in them at time of loading app, and when new data is added/changed in database, that data is added/updated in respective Hashmap.

Now this was working fine as there was only one war so sharing was simple.

But now there are 3 different wars and one Ejb under single Ear and all them needs to share data concurrently.

so I need some way to keep this data at some place from where all wars and Ejb can access them without interfering.

I'm having JSP-Servlet applications with maven and server used is Jboss-7.1.1.Final.

Please suggest me best way to make this work.


Solution

  • You could use a Singleton or ApplicationScope component holding your cache and let it inject by each application in your WARs.

    Alternatively, you could build a REST service around your Cache and use it by each application.

    But still, I would suggest not to try to build your own cache. You could use standard JPA, still load all records at start and then let the JPA implementation do the caching for you - there won't be many database hits for data which does not change.