aspose file tools*
The moose likes Servlets and the fly likes Loading a cache in servlet init method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Loading a cache in servlet init method" Watch "Loading a cache in servlet init method" New topic
Author

Loading a cache in servlet init method

Jaideep Kshirsagar
Greenhorn

Joined: Aug 29, 2007
Posts: 27
Hi,

I am loading a cache in 'init' method of servlet. The cache holds various exceptions which are sent to different exception buckets on screen.

Now as the number of exceptions are too high, it takes a long time (around 30 min) to load the cache. Untill the cache is loaded the servlet does not show up.
So servlet start up time is causing performance issues.

Is there any way through which first exception cacheing is handled by some script or different method in servlet and then the servlet comes up?

How to reduce the start up time for this servlet, considering amount of cacheing required? Please let me know if any more information is required.

TIA.

Rgds,
Jai
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42599
    
  65
Does the servlet need the cache for its work? If so, I don't see a way around waiting for that time until it can assume operation. If not, I'd move the cache initialization to a ServletContextListener that runs independently of any servlet.


Ping & DNS - my free Android networking tools app
Jaideep Kshirsagar
Greenhorn

Joined: Aug 29, 2007
Posts: 27
Hi,

Servlet uses the cache in doGet method, any option through which I can load the cache before servlet startup just use it in servlet?

Regd,
Jai
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

1) attack the load method to see if you can speed it up
2) make the cache load in a separate thread and only make the loaded parts available to the Servlet
eg

3) once again load in a separate thread, but allow the SErvlet to load the data it needs too

Note that it is not always a problem if the data gets loaded from both sides.
4) Don't use caching

if you let go of the idea that the cache needs to be 100% before it is useful, you can slowly improve your performance while the cache fills.
Imtiyaz Ahmed
Greenhorn

Joined: Dec 03, 2007
Posts: 3
u may get benefitted by using <load-on-startup> tag in DD.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61610
    
  67

Originally posted by Imtiyaz Ahmed:
u may get benefitted by using <load-on-startup> tag in DD.


Please use real words when posting to the forums. Abbreviations such as "u" in place of "you" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Jaideep Kshirsagar
Greenhorn

Joined: Aug 29, 2007
Posts: 27
Hi,

I am not sure how <load-on-startup> tag will benefit me in this case, I am already using it with value as '1', as the concerned servlet should be the first one to get loaded.

The problem is that due to cacheing happening in 'init(servletConfig)' method, load up time is shooting up.

I dont have a fare clue if a perl script can do my job (cacheing) beforehand and I can just use the object wherever required. I am also not definitely aware if using 'init()' method for cacheing will help. Any insights on this?

Rgds,
Jai
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61610
    
  67

Originally posted by Jaideep Kshirsagar:
I am not sure how <load-on-startup> tag will benefit me in this case

It won't. Context listeners have made load-on-startup obsolete for pre-initializing web apps.
Sanjay Kannan
Greenhorn

Joined: Nov 25, 2007
Posts: 16
"The cache holds various exceptions which are sent to different exception buckets on screen."

What data does the cache contains. You might want to do lazy initialization. Load the cache with data which has been used, so you can prevent the loading of huge data when the servlet starts up.

But i am not sure if you need all the data for display or something that sort.
Jaideep Kshirsagar
Greenhorn

Joined: Aug 29, 2007
Posts: 27
Hi,
This information may be of help -

The cache holds various exceptions which are sent to different exception buckets on screen.

This means that it is a gui to display exceptions occured while processing.

What data does the cache contains.

Cache consists of various hashmaps containing exception objects of various types.

But i am not sure if you need all the data for display or something that sort.

Yes, I would need the entire data for displaying exceptions on screen.

Thank you,
Jai
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Loading a cache in servlet init method