Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

servlet context

Posted on 2003-12-02
5
Medium Priority
?
765 Views
Last Modified: 2010-04-01
Hi Experts,

I am currently storing a few lists such as contry codes and languages etc in the servlet context when the server starts up.
This helps me in saving unnecessary connections to the database.

Can I update the servlet context if I add a field in the database without stopping the server.
by accessing it like a session variable.

Kindly advise.
Thank you for your help
0
Comment
Question by:applekanna
  • 2
  • 2
5 Comments
 
LVL 35

Accepted Solution

by:
TimYates earned 300 total points
ID: 9858949
Yes, assuming you have one instance of the servlet which loads the information (singleton), you can store this instance in a static variable inside the servlet, then call this method when the database is updated to update your records...

OR, you can have a TimerTask which runs every hour or so, connects to the database, and refreshes the list

or a combination of the two...

can you post your code which does the servlet context work at the moment...we should be able to extend it

Also, is the database being updated via the same webapp?  Or are you putting new values in from another application (or the SQL console) ?
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 9858967
what do you mean update? add variables? change values? if so... then yeah.

just do as you would w/ the session object:

from either a jsp or servlet:

getServletContext().setAttribute(<key>, <val>);

0
 
LVL 3

Author Comment

by:applekanna
ID: 9859070
Oops sorry for not making the quetsion clear.

I have a list of country names in my appllication servlet context loaded from the DB.
If my manager adds a new country to the table I should be able to show that too without stopping the server.

What I had in mind was
 at a singleton init servlet  load the servlet context

whenver a record is added or removed, remove the servelt context variable , reload it from db and then set  it again.

like session.getAttribute("countryList");


      session.removeAttribute("countryList");
//load country list vector from db and then
      session.setAttribute("countryList");
Similary can I do with servelt context . Is there any issues I need to be aware of ..

Thank u.
0
 
LVL 35

Expert Comment

by:TimYates
ID: 9859212
> What I had in mind was at a singleton init servlet  load the servlet context

Yup :-)

> whenver a record is added or removed, remove the servelt context variable , reload it from db and then set  it again.

Reload from db into list
replace attribute

servlet.getServletContext().setAttribute( "countryList", list ) ;

if you replace instead of reove, get then add, you won't get that short period where there is no list :-)

0
 
LVL 3

Author Comment

by:applekanna
ID: 9860160
thx for your comments :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Did you know there are services out there that can turn an Instagram feed into an RSS feed? I found some interesting exclusive Instagram content which I wanted to follow without signing up for yet another social media account. RSS to the rescue!
In this article, the configuration steps in Zabbix to monitor devices via SNMP will be discussed with some real examples on Cisco Router/Switch, Catalyst Switch, NAS Synology device.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses
Course of the Month10 days, 5 hours left to enroll

926 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question