• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Load objects on session upon restart

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I have objects that I would like to load in session upon tomcat restart.

How would I do that?

Thanks in advance!
 
Ranch Hand
Posts: 134
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Erap Estrada:
Hi. I have objects that I would like to load in session upon tomcat restart.

How would I do that?

Thanks in advance!



You can't do this, exactly, since when the container restarts, there aren't sessions in existence ( Someone please correct me if I'm wrong ). You'll have to wait for the client to participate in a session first.

You could use the sessionCreated() event of the HttpSessionListener to populate your session with appropriate data.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tomcat can serialize sessions to disk so they will survive if you shutdown and restart. I suspect they wont be reloaded until needed.

What sort of objects are you needing to load? If we are talking about user specific data there are better ways of ensuring long term data storage than the session mechanism.

Bill
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Tarun.

I need to load an array of java beans.

Can you please lead me on how to properly implement this?

Thanks!
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You want to load the array of beans when the session is created or when Tomcat starts/restarts?

When Tomcat initially starts, there won't be any sessions.
When it restarts, if your code allows it, it will deserialize any sessions that existed when it was shut down; but those sessions had to already exist.

If you can explain why you want to do this, maybe someone can suggest a better alternative (or, if we're misunderstanding you, maybe it would make things more clear for us).
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My site list in the homepage like "Top 10 Retail Stores". This information is available to all users and changes about every other day.

What I did is, in my index page, I retrieve those data and save it to session. So whenever user access the data, it is readily available.

I just wonder if there's a better way to do it without invoking any of my web pages.

Thanks!
 
William Brogden
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

This information is available to all users and changes about every other day.



If the same information is available to all, it certainly doesn't need to be repeated in each user's session. Sessions are for data unique to each user.

This collection of bean objects could be loaded as a ServletContext attribute.

The ServletContextListener interface looks like a great candidate for a custom class to load the collection on startup and save it when the server is shutdown.

Bill
 
Erap Estrada
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I knew it. There's a better way. Thank you Bill. I'll research on that and I'll post questions on things that are unclear.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic