Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Are managed-beans shared?

 
Henrique Sousa
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, fellas

I was thinking about some things, and I am not sure about how JSF manages my beans. I know that a managed-bean stored in session scope is shared throughout all requests in that user's session, but what about request scope managed-beans? Are they pooled or even shared accross multiple requests? I need to know if it is safe to use instance variables in my backing beans. I know it does not work for Servlets and Struts but, hey, this is JSF! Clarifying is very appreciated
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The simplest thing to do would be to place a System.out.println in your bean's constructor and find out... And what you would find is that request scope beans are not reused -- they are constructed when needed. These beans are usually there to back a HTML FORM, so they are cheap to construct -- there should be no need to "optimize" this by pooling or reuse -- that would only slow things down!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic