• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Does bean used by a jsp need to be threadsafe?

 
Stefan Elfvinge
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If a jsp uses a bean with session-scope,
does that mean that the bean only can be referenced from this session or does it mean that every thread requesting the jsp has access to the SAME bean? The main question is: does the bean need to be threadsafe, or does the container instansiate new beans for every session?
Here's an MVC question: Not using EJB:s, would it seem like a good idea letting a servlet choose view depending on request-parameters and set bean-properties before dispatching to the view(jsp), then the jsp simply uses getProperty() against the bean??? If the beans properties needs to be set with db-data, who should have the responsibility to access the db? Servlet or the bean itself? What would be a normal approach?
Thanks!(newbie to MVC and jsp:s)
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Stefan Elfvinge:
If a jsp uses a bean with session-scope,
does that mean that the bean only can be referenced from this session or does it mean that every thread requesting the jsp has access to the SAME bean? The main question is: does the bean need to be threadsafe, or does the container instansiate new beans for every session?

If the scope is set as session then the instane of the bean that you create will be placed in the session object. Any other sessions that access the same page would get their own instance of the bean. Where you could run into problems is if you have any static members in the bean class itself, those could be accessed by different sessions and could cause a problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic