This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading Data at app startup  RSS feed

 
subhadeep chakraborty
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a situation where on each login huge data is fetched from database and stored into the users session. I do not want the database query to run every time and want to load the data at application startup in applicaion scope thus making session contain less data and also decreasing the database query time. My whole application is getting the data currently from session and I donot want to change it. Is there a way to do this ?
Is it possible to override weblogic 10.3's HttpSession implementation and override getAttribute() to do my work.

Thanks,
Subhadeep
 
Martin Vanyavchich
Ranch Hand
Posts: 241
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I understand you correctly you need just one copy of that data, and it should be fetched only once. You could put the data in a static variable, check if it's empty and fill it form DB.
 
Sunil Kumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In a web application, people typically do this in servlet and load that servlet on startup using web.xml like


 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A startup listener should be preferred to an init servlet
 
Sunil Kumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rather than servlet use listener. Read the comment from Ben Souther
http://www.coderanch.com/t/361567/Servlets/java/load-startup-tag-Vs-listener
 
Sunil Kumar
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, right David. http://www.coderanch.com/t/361567/Servlets/java/load-startup-tag-Vs-listener will help differentiate amongst the two as i said above.
Thanks David.
 
Campbell Ritchie
Marshal
Posts: 55677
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to servlets forum.
 
subhadeep chakraborty
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
Thanks for you response.My existing application gets the data from session and if I store the data in application
context I shall have to go through the whole application and change.I do not want to do that.

Is it possible to override weblogic 10.3's HttpSession implementation and override getAttribute() to do my work.

Is there a different way?

Thanks,
SUbhadeep
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Applying a band-aid that will make your code fragile and confusing is not the best approach. Take the time to refactor the code properly.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!