1

I have no code done yet but I'm thinking on how I'm supposed to do this in JSP/JSF.

So, I have some classes I was thinking I could load from a DB whenever the session starts. My first idea is that I just load them once with the necessary data from the DB, do all the operations, and then destroy the bean when the session is done. The problem is, what if another user changes information during the session? So I thought I could use a page scope, however I don't want to overload the server.

What's the best practice on this?

A_nto2
  • 1,106
  • 7
  • 16
Carlos Vergara
  • 3,592
  • 4
  • 31
  • 56
  • You could load the data in a cache library like ehcache, and configure it to reload data based on time or another of the alternatives the library could offer to you. Also, if this data could be shared among users, its not good to have it in session, maybe in application scope. – Luiggi Mendoza Jul 24 '12 at 04:59
  • I'm checking how EHCache works, thank you! – Carlos Vergara Jul 24 '12 at 05:25

2 Answers2

0

Firstly, each visitor to your app gets their own session-scoped bean, so you've only got to worry about persisting each user's changes to the data on the bean.

Secondly, you are worrying about matters which are taken into consideration by ORM offerings. Using the API provided by something like Spring JPA or Hibernate will present you with controls for persisting data changes back to the DB via a local handle on a Bean.

8bitjunkie
  • 12,793
  • 9
  • 57
  • 70
0

I decided to use an application scoped bean instead of a singleton class. That will do.

Carlos Vergara
  • 3,592
  • 4
  • 31
  • 56