• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Does bean used by a jsp need to be threadsafe?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic