Hey Stanley.. things who's scope are "application" are shared by all of the
users using the webapp at the same time.  So if you and I are both running
that page, there's a chance that we'll try to access that bean at the exact
same time.  Because of that, it has to be synchronized, so that only one
person can do it at a time.

Session beans don't have to be synched, because there is 1 instance of that
bean per user.  So in that case, you have an instance of sessionCounter, and
I have an instance, so we don't share one between us.  In that case, there's
no need to synchronize, since we each have our own copy.

Hope this helps,
Roy

----- Original Message -----
From: "Stanley Tan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, April 05, 2001 3:07 AM
Subject: Synchronization Issues


> Hi all,
>
> Following jGuru's "Introduction to JavaServer Pages Technology", I have
> come across the following code:
>
> <%@ page import="CounterBean" %>
>
> <jsp:useBean id="sessionCounter" class="CounterBean" scope="session" />
> <jsp:useBean id="applicationCounter" scope="application"
class="CounterBean"/>
>
> <%
>      sessionCounter.increaseCount();
>      synchronized (page) {
>          applicationCounter.increaseCount();
>      }
> %>
>
>
> Why is the sessionCounter not synchronized but the applicationCounter
> is?  And why is applicationCounter synchronized on "page" instead of on
> "application"?
>
> Thanks for your help.
>
> Stanley Tan
>
>
===========================================================================
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
> For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
>  http://java.sun.com/products/jsp/faq.html
>  http://www.esperanto.org.nz/jsp/jspfaq.html
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
>  http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
 http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets

Reply via email to