0

I have a JSF application with a @ViewScoped bean. It is viewScoped because I do some ajax requests.

I load a big amount of data into the view and display it to the user.

Today I performed a load test and I ran into an OutOfMemoryException. As it turns out, when I open the page, @PostConstruct is called

bean created. ID = @54a35e23

Now I navigate to another page and return again (@PreDestroy was not called) Then I get

bean created. ID = @fee0948

I do this all over again in the load test. And a few hours later I have the OutOfMemoryException

Can I somehow force JSF to destroy my ViewScoped bean when I navigat to another page?

matthias
  • 1,938
  • 23
  • 51
  • Do you use CDI or are you open to? OmniFaces `@ViewScoped` explicitly destroys beans and associated JSF view state during onload. But it requires CDI. See also http://showcase.omnifaces.org/cdi/ViewScoped – BalusC Apr 07 '16 at 12:44
  • I use java ee 6 and no CDI. Additionally I am very close to go live so I don't want to change lot. Is there no other way? – matthias Apr 07 '16 at 12:47
  • JSF (Mojarra) keeps a max of 25 view scoped beans in session. Alter memory space on that. Or, introduce 2nd level JPA cache (if you're using JPA). – BalusC Apr 07 '16 at 12:52
  • can I somehow reduce 25 to 3 ? – matthias Apr 07 '16 at 12:54
  • Not without hacking the impl. There's no public setting for that. – BalusC Apr 07 '16 at 12:55
  • I disabled the JPA L2 cache because of stale data in my cluster – matthias Apr 07 '16 at 12:57
  • @BalusC when you say it stores 25 view scoped beans. That means when I refreh the page for the 26th time, the 1st view scoped beans's PreDestroy method should be called, correct? – matthias Apr 07 '16 at 13:04
  • It will evict physical bean from LRU map in session, no worries, but whether its `@PreDestroy` method is called depends on JSF version. This is only fixed since 2.2. See also OmniFaces `@ViewScoped` javadoc/showcase for explanation/links on this problem. – BalusC Apr 07 '16 at 13:07
  • okay thanks. I wonder, would it be a good idea to change from viewScoped to SessionScoped? Therefore it would not create so many instances – matthias Apr 07 '16 at 13:19
  • Depends on scope of the data. See also http://stackoverflow.com/q/7031885 – BalusC Apr 07 '16 at 13:20

1 Answers1

0

If you ViewScoped bean is huge, you have a problem with your implementation. Could you add your source to review it. If you're handling a huge data amount, you probably need to use something in memory grid like Infinispan or Hazelcast

Rene Enriquez
  • 1,418
  • 1
  • 13
  • 33