• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What should a Servlet do if its loading a resource on load time that is taking time

 
Yasir Karim
Greenhorn
Posts: 17
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assume that resource loading takes 2 minutes and we need to handle the situation when a request comes at that stage. I doubt a Servlet should be throwing UnavailableException in the subject case.
 
Durgesh Vaishnav
Greenhorn
Posts: 16
Java Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding Caching logic in servlet for requested data. This might help on subsequent requests.
 
Tim Moores
Bartender
Posts: 2675
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move that initialization code to a ServletContextListener - the web app won't accept request until it is run, so you won't have this problem.
 
Avinash Ga
Ranch Hand
Posts: 78
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can make your servlet to load the resource at the start up itself by using <load-on-startup>1</load-on-startup>. this will load the resource at the time of the servlet context creation (way before any requests)
 
Yasir Karim
Greenhorn
Posts: 17
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks everyone.
When should a Servlet be throwing UnavailableException then?
 
Avinash Ga
Ranch Hand
Posts: 78
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yasir Karim wrote:Thanks everyone.
When should a Servlet be throwing UnavailableException then?


The case in which your application tier is down, and the servlet is unable to process the request without application tier the servlet can throw UnAvailableException. UnAvailableException is thrown to indicate the client code to say "Something Fishy" in the request processing. so that client can take corrective action. if there are now corrective actions then the client is let to have a time out.

Best Wishes
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic