0

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.

1
  • 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?).
    – mabi
    Nov 29, 2013 at 8:53

1 Answer 1

0

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
1
  • Unfortunately the problem is severe, since each of the baking beans starts a very heavy operation on the server (running full hardware emulator).
    – azerIO
    Aug 28, 2012 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.