Bruno
Bruno

Reputation: 669

How to share same static data objects in Java Web Application?

I want to develop a Web browser game in Java (with Struts or Spring) but I have two questions: - Do you think Java with struts or spring is a good choice? (If no, why?) - Some configuration data (like the planets and their properties are immutable) should be loaded one time from the database and stay in memory shared by all the requests. What do you recommend for this? Should I put all the configurations data in servlet context?

Thank You.

Upvotes: 2

Views: 423

Answers (2)

mprabhat
mprabhat

Reputation: 20323

Struts or Spring good choice ? Yes, both are pretty matured, have huge community, they are open source(if you need can check there code), You should also check out JSF, I personally like Primefaces (JSF component library), GWT or Eclipse RAP are other options available.

Configuration Data in Servlet Context :

Why would you make your servlet context so heavy, you should consider having a cache for such scenario. Have a look at EhCache for example.

As per comment:

You can even try creating your own cache to hold your data from DB, something like a Singleton Class holding your data say in a Map

Upvotes: 0

rk2010
rk2010

Reputation: 3529

*Assuming that you going to create a Spring App, but haven't decided whether to choose Struts or SpringMVC.

I would recommend Spring MVC, mainly because if you are going to be choosing Spring as your container, then you might as well choose Spring MVC, instead of plugging Struts into Spring Container.

About Properties: Config properties are not something I would NOT store in DB. Instead, I suggest you create *.properties files.

You could have a class with a public static final HashMap. Also make the Hashmap unmodifiable. Populate that HashMap with the contents of the properties file.

Of course, the better way in a Spring app, would be to create a singleton Spring bean, that loads the properties at initialization.

Upvotes: 1

Related Questions