• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Browser time outs for long running back end process

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Saloon Keeper
Posts: 27763
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Tim very much! I'll start examining the technicalities of your approach
 
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic