• Post Reply Bookmark Topic Watch Topic
  • New Topic

Browser time outs for long running back end process  RSS feed

 
Dimitris Karageorgopoulos
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Gurus,

I have a JSF page that invokes a long running backend process using EJBs.
After a certain amount of time the browser timesout displaying an 'Oops broken page' message.
Does anybody know how to make the JSF page resilient to the back end long running process?

I use Oracle OC4J as my application server
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This isn't a JSF problem, it's a fundamental HTTP problem.

HTTP is not designed to be a client/server session-based protocol. It's a quick-response one-off protocol that simulates sessions by the use of various tricks. Effectively, each time you hit submit, you connect, get a response and disconnect and it's only thanks to those tricks that the next request can be related to the previous request.

Because HTTP is designed as a quick-response protocol, you should not attempt to execute long-running processes in HTTP request-processing code. You not only will time out browsers, you will hog critical server resources. Nor should you attempt to spawn threads off the request-processing code, because the request threads are pooled and may not (per the J2EE spec) spawn child threads.

To handle this common problem, you need to set up an independent processor outside of the HTTP request/response processors and let it manage long-running tasks. The HTTP processors then become responsible to entering requests to the backend engine and monitoring and controlling the backend engine.

A popular way of doing this is to spawn a thread from a ServletContextListener when the webapp starts up. Unlike HTTP processors, the ServletContextListener thread is permitted to do this. That thread can then run the engine, which typically maintains a request processing queue that HTTP request processors add backend processing requests to. The engine then pulls requests from the queue and hands them off the the code that actually does the long-running process.

As I said, this is a very common problem. In fact, I have to do one of them this week!
 
Dimitris Karageorgopoulos
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Tim very much! I'll start examining the technicalities of your approach
 
Brendan Healey
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Tim says , this is a complicated area. Presumably what you're seeing is not an "oops"
message but a ViewExpiredException, which is triggered after a period of inactivity on the
session. The session timeout is specified at the application level in the web.xml as such
(in minutes):



You are able to override this setting in your code like this:



To handle a ViewExpiredException you need to implement a CustomExceptionHandler. It is not
possible to setup an error page in the web.xml to handle this exception type. There is an example
in Ed Burn's book JFS 2.

Regards,
Brendan.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!