Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Auto-run servlets?  RSS feed

 
Jason Kwok
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've built a web application that currently runs a servlet (to load application wide variables) whenever a user goes to my index.html page.

However, I'm not sure having each user call this servlet everytime they come to the page is such a good idea. Would it slow down the application? Would there be problems when multiple users go to the index page all at once?

So, as opposed to having this servlet being called everytime a new visitor comes to the site, is it possible to have the servlet be called just once a day? (simply just to refresh those variables)

Any advice on this would be greatly appreciated!!

Thanks,
Jason
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Jason Kwok:

I've built a web application that currently runs a servlet (to load application wide variables) whenever a user goes to my index.html page.


Why would you want to load the application-wide variables more than once when the app is started?

You can do so easily through use of a context listener.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the variables need to be refreshed daily (do they come from a DB?), you can also write an admin servlet that can call the same logic that the context listener uses to load the variables, and then schedule a cron job that uses wget to "hit" the servlet daily.

There are security implications here. You probably don't want just anyone to be able to reload the variables.
[ March 14, 2006: Message edited by: Bear Bibeault ]
 
Jason Kwok
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

The variables are actually news items that are stored on the database. I used this 'start up' servlet to load those news items across the entire application because they are used by several different JSP pages.

This web application is going to be put on a server and actually used. Prior to this project, I've only made web applications with tomcat, running solely on my own computer meaning only I could see it. In that case, loading the variables when the index.html was called suited my needs at the time.

Now that this new web application will be live and running 24/7, a call to refresh and update the variables is necessary on a daily basis.

For example, each news item has a creation date that is stored on the database. My clients want news items to be published for two weeks and then be removed, and not by an administrator... the removal has to be automatically performed instead. So I figured a servlet checking dates, and then reloading the news items that are still under 2 weeks old weeks old is how I could accomplish this.

As you can see, I'm a little lost. I'd appreciate any help you could offer!!

Thanks again,
Jason
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65830
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well for keeping the app variables up-to-date on a daily basis, what I've already written is one solution to your problem.

For flushing old information from the DB, I wouldn't do that in the web application at all. Rather, I'd have a daemon process running on the server that would wake itself up daily (or whatever interval was appropriate), connect to the DB, and clean out the stale information.
 
Jason Kwok
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's great Bear, thank you!!

Just so that I'm clear however... you posted two possible solutions earlier. Did you mean using a context listener? Or the cron job?

Thanks,
Jason
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!