this synchronization thing with jsp/servlets is very confusing and complex issue..
If, for example, I have following simple class Person, which interacts with DB..
And finally to my question. Is this thread-safe? Should I do some synchronization or not? Especially with the connection fetched from the connection-pool. Do every thread get it's own "copy" of the test.PersonBean-class? Or do they share it some way? If, for example, I declare <jsp:useBean id='JSP_person' scope='APPLICATION' class='test.PersonBean'/> then do every JSP-thread share this bean and it's information (class)? Am I right or wrong? What Im basicly asking is that do servlets/jsp -threads get their own "copy" of objects when running? Another question would be that when to use synchronization-keyword with servlets/jsp-pages?
Every answer would be greatly appreciated.
ps. I would also appreciate some GOOD internet-resource concerning threads, jsp-pages, servlets, deadlocks and synchorization. So if you know any, please let me know, thanks..
I declare <jsp:useBean id='JSP_person' scope='APPLICATION' class='test.PersonBean'/> then do every JSP-thread share this bean and it's information (class)?
Yes. Declaring the scoped variable in application scope makes it available to the entire web app. If that's not what you want, don't use application scope.
What Im basicly asking is that do servlets/jsp -threads get their own "copy" of objects when running?
Servlets and JSP are no different than any other Java application. If you declare local variables in a thread, they are local to that thread. if you share "global" variables across threads, that's when you start running into contention issues.
Originally posted by Vishnu Koya:
It will be automatically synchronized and web container uses different copy of jsp-person bean though in application scope. This is what I think. Any corrections/ideas are welcome.
Completely incorrect. Again, any scoped variable placed into application scope is shared across the entire web application. That's the reason for the existence of application scope. There is no automatic synchronization.