Forums Register Login

JSP threads and synchronization

+Pie Number of slices to send: Send
hello, could someone help me please

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..
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
 

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.
It's exactly the same and completely different as this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 2820 times.
Similar Threads
What is good practice for FORM VALIDATION ?
<jsp:useBean> conditional body
bean problem
UseBean error
use of value object ( javabeans )
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 02:22:28.