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
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