Elimine el bean ViewScoped si el usuario cierra el navegador incorrectamente (terminación instantánea del navegador)

Imagine a situation where user works with some JSF page which makes use of a ViewScoped backing bean. In case of navigation to a different page within the application the custom destructor (i.e. @PreDestroy) of the bean will be called automatically. In case of the user closing a tab/window properly one can invoke a remote command at the server via AJAX in order to free the bean.

However, what if simply the power fails on the user side and PC is turned of instantly or the browser gets terminated improperly such that no JS code can be invoked. This implies that the bean will hang on the server side forever using its resources. How can such problem be solved?

One of the solutions I think of is to put a PrimeFaces poll element on the page which would "ping" the managed bean via remote command. If the bean notices a timeout then it will terminate itself freeing all resources. Is there any better solution for this problem? Thx.

preguntado el 28 de agosto de 12 a las 11:08

It isn't an answer to your question, but if your backing bean is that "heavy", consider having a EJB pool that does the actual business logic, eg. have the view bean communicate commands to the emulator run by an EJB (pool?). -

1 Respuestas

Basically, ViewScoped beans wont last longer than the session. The session timeout is configurable, so the beans wont "hang on the server side forever".

You could, however, implement a polling based solution to free memory used by view scoped beans. But since sudden power loss and even accidently closed browsers occur rather seldom (compared to the "normal" usage), the waste of resources directly resulting from polling will be much more expensive than the wasted memory.

Long story short, the problem is inexistent if:

  • you are using client side state saving
  • you are using server side state saving and session timeout is configured properly

Respondido 28 ago 12, 12:08

Unfortunately the problem is severe, since each of the baking beans starts a very heavy operation on the server (running full hardware emulator). - azerIO

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.