0

To reduce database hits, I've used static variables to store data from database. At time of WAR deployment this data is stored in these variabes as it is not changing so frequently. This scenario was working fine as the scope was with only single a WAR. Now I have another application where I need access to these varibles But due to different application scope,I'm unable to access them in another application.

Also I'm having an EAR which encloses both above WAR and one JAR containing some common buisness logic of both WARs. So under EAR is it possible to share these variables via JAR or using some different approach?

If any javaEE concept can help in this scenario, then please let me know about it also.

I'm using maven with Jboss7.1.1.Final for this

Mike Baxter
  • 6,868
  • 17
  • 67
  • 115
vg123
  • 235
  • 2
  • 3
  • 13

2 Answers2

1

You should use Infinispan, the built-in caching mechanism of JBoss 7 https://docs.jboss.org/author/display/ISPN/Getting+Started+Guide+-+JBoss+AS+7. Caching data in static fields is generally frowned upon in Java EE.

However should you still want to cache your data in static fields you need to make sure the class with the cache was to be shared across all WARs. This means you have to create skinny WARs.

Philippe Marschall
  • 4,452
  • 1
  • 34
  • 52
1

Looks like you need an Enterprise Caching Solutions. There are lots of choices on the market. They include but not limit to

Open Source framework

  1. Memcached
  2. EHCache
  3. Infinispan (mentioned by Phillipe)

Commercial product

  1. Oracle Coherence
  2. GigaSpaces XAP
  3. GemFire

For your second question, as long as your JAR is deployed in the EAR/lib folder, you should be fine.

Lan
  • 6,470
  • 3
  • 26
  • 37