File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes What should a Servlet do if its loading a resource on load time that is taking time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "What should a Servlet do if its loading a resource on load time that is taking time" Watch "What should a Servlet do if its loading a resource on load time that is taking time" New topic
Author

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

Yasir Karim
Greenhorn

Joined: Jul 21, 2011
Posts: 17

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.


I see the truth in the code.
Durgesh Vaishnav
Greenhorn

Joined: Oct 06, 2006
Posts: 16

Try adding Caching logic in servlet for requested data. This might help on subsequent requests.


Enthusiasm is the engine of success!!
SCJP 1.4, OCPJP6
Tim Moores
Rancher

Joined: Sep 21, 2011
Posts: 2408
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

Joined: Aug 13, 2011
Posts: 78

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)


Avinash G.A
OCP Java SE 6 Programmer, OCP Java EE 5 Web Component Developer, OCE Java EE 6 Web Services Developer, VMware Certified Core Spring 3.x Developer, EMC Proven Professional (ISM-V2)
Yasir Karim
Greenhorn

Joined: Jul 21, 2011
Posts: 17

Thanks everyone.
When should a Servlet be throwing UnavailableException then?
Avinash Ga
Ranch Hand

Joined: Aug 13, 2011
Posts: 78

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What should a Servlet do if its loading a resource on load time that is taking time
 
Similar Threads
JavaMail and bundles
ControllerServlet Not found
Tomcat loading servlet ..twice..
quick questions
static block