Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing Servlet Context

 
Ratheesh Narayanan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

How costly is it, to retrive a string data from ServletContext on every request?

I have a RequestListener which will retrive two string values from a ServletContext on every request and data in these strings will be same across all the requests, it doesn't change. What would you suggest? Write a raw code to fetch out the strings on every request or a wrapper data object which maintain the strings once its initialized?

Thanks in advance!
Ratheesh
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any particular reason you can't store the values in static fields in the listener object?
 
Ratheesh Narayanan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it's a good decision!

Even I was thinking of maintaining this in a static field, but it was not primary solution for me, till I see your reply. You made me to re-think.

Thanks a lot!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic