Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

J2EE and jdbc desinge

 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all:
I have 2 question, and I really appreciate any suggestion from experieced developers.
1- If I have a certain set of information in the database, which I need it almost in every page I display (for example: a list of the functions available to a certain user) is it adeqaute to bring all this data and store it in the serverlet context object, so that it will be availabel to all other servlets? If I use this approch, if the information in the database changed, how can I change it in the application servlet context without rebooting the server? Note: consider a clustered application server.
2- If the first approche is not adequate, how can I approche the this problem? How can I make infomation available to every page and servlet without quering the database every time a user request a page?
Not: The size of information is large, and it is confidinial, so I can't store it in a flat file.
thank you all
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the application is distributed, ie the <distributable/> tag is set in web.xml, then you may have several VMs running the application and neither the servlet context nor events of servlet context are propagated when the container decides to create a new VM. In that case the Servlet Spec says that you should use the session object, a database or EJBs. If you have huge amounts of data as you indicate, storing in each session object would probably be a bad idea. My instincts on this one is to use a stateless session EJB using a local interface and BMP. You would make the JDBC calls in the session bean and cache the data there upon creation. No entity beans would be involved and since you are using a local instead of remote interface performance would improve greatly. Now this assumes that the database doesn't change every few seconds or even minutes. You could then refresh the session bean data cache at a predetemined interval. There may be instances when the bean's data cache is stale but the only alternative is to hit the database every time.
This belongs in the Servlet forum, so I am moving it there.
[ April 03, 2004: Message edited by: Michael Morris ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hanna,
Is the data specific to each user or is it for everyone as a whole? If the data is used by everyone, you can store it in the application scope. (singleton or static variables) Similarly if the user has some sort of "type", you can store the large data in one place and use a function call to get what is needed for the specific user. The point of this is to minimize the amount of shared data in the session.
If the data really is unique per user, do what Michael said.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Jeanne :
The data is shared among many users, however every user group has a distenct set of data. If I store it in the application scope, how can I update it when the database changes without redeploying the application? also, consider a clusterd application server. I created a servlet that go to the database and bring the new data, however, it doesn't work in a clustered application server. Only one VM get the new data, the others don't know anything about it. As was suggested here, EJB will be one solution, but I don't have experiece with EJB nor any one on my team.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34178
340
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hanna,
Caching could help you out here. You could refresh the cache every set time interval. Or you could have a database table with a "last updated" time and refresh the cache if the time is greater than the most recent time the cache was loaded.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic