Well there you have it... Thanks Drew.

I still would like to know if JRun does it for you like Tomcat does, because
if you double lock you could cause a dead lock.

_____________________________________________
Pete Freitag ([EMAIL PROTECTED])
CTO, CFDEV.COM
ColdFusion Developer Resources
http://www.cfdev.com/


-----Original Message-----
From: Drew Falkman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 9:20 PM
To: JRun-Talk
Subject: RE: Do application variables need locking?


Well, I couldn't help myself. This is a pretty big issue and I had to know
the answer - it is not in the Servlet 2.3 specification. An excerpt from the
Session section:

"J2EE.7.7.1 Threading Issues
Multiple servlets executing request threads may have active access to a
single session object at the same time. The Developer has the responsibility
for synchronizing access to session resources as appropriate."

Developer is us, Container Provider would be Macromedia (though they aren't
mentioned here...)

Servlet 2.2 is the same:

"7.7.1 Threading Issues
Multiple servlets executing request threads may have active access to a
single session object at the same time. The Developer has the responsibility
to synchronize access to resources stored in the session as appropriate."

So there you are - it is up to us... Macromedia is obliged NOT to provide
thread safety in order to be compatible with the J2EE spec.

-Drew Falkman
Author, JRun Web Application Construction Kit
http://www.drewfalkman.com/books/0789726009/


-----Original Message-----
From: Haseltine, Celeste [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 3:25 PM
To: JRun-Talk
Subject: RE: Do application variables need locking?


Pete,

That's a good question.  One place you might check out is the Sun Servlet
standard, and see if synchronization of the attributes is required for any
Sun compliant servlet container.  If it is, and since JRUN 3.1 is Sun
Servlet 2.2 compliant, then I would assume that JRUN 3.1 would also
synchronize the attributes.  Make sure that you check out servlet standard
2.2 and not 2.3 (which is available on the Sun site), as JRUN 3.1 complies
with servlet standard 2.2.

Celeste
-----Original Message-----
From: Pete Freitag [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 5:09 PM
To: JRun-Talk
Subject: RE: Do application variables need locking?


I was kind of curious so I checked out the latest Tomcat source and they do
synchronize the attributes...  Anyone know if JRun does?

Code from Tomcat's StandardSession object...

public Object getAttribute(String name) {

        if (!isValid)
            throw new IllegalStateException
                (sm.getString("standardSession.getAttribute.ise"));

        synchronized (attributes) {
            return (attributes.get(name));
        }

    }

_____________________________________________
Pete Freitag ([EMAIL PROTECTED])
CTO, CFDEV.COM
ColdFusion Developer Resources
http://www.cfdev.com/


-----Original Message-----
From: Drew Falkman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 5:45 PM
To: JRun-Talk
Subject: RE: Do application variables need locking?


I would assume so, but haven't tried.

-Drew Falkman
Author, JRun Web Application Construction Kit
http://www.drewfalkman.com/books/0789726009/

-----Original Message-----
From: Pete Freitag [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 2:45 PM
To: JRun-Talk
Subject: RE: Do application variables need locking?


Yeah I sort of assumed it was as well.  Do any Servlet Implementations (such
as JRun) synchronize their implementation of the HttpSession interface? it
would probably be very easy to just declare the hashtable for the attributes
as synchronized.  The same for the ServletContext/application
implementation?

_____________________________________________
Pete Freitag ([EMAIL PROTECTED])
CTO, CFDEV.COM
ColdFusion Developer Resources
http://www.cfdev.com/


-----Original Message-----
From: Drew Falkman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 5:25 PM
To: JRun-Talk
Subject: RE: Do application variables need locking?


That's a good question - I actually thought that it was for a while. I do
know that synchronization basically kills the ability to scale. It's single
threaded...

-Drew Falkman
Author, JRun Web Application Construction Kit
http://www.drewfalkman.com/books/0789726009/

-----Original Message-----
From: Pete Freitag [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 2:26 PM
To: JRun-Talk
Subject: RE: Do application variables need locking?


Drew,

        Why isn't the session object (HttpSession) just synchronized in the
servlet
API? I can't think of a reason why it shouldn't be (performance?).

_____________________________________________
Pete Freitag ([EMAIL PROTECTED])
CTO, CFDEV.COM
ColdFusion Developer Resources
http://www.cfdev.com/


-----Original Message-----
From: Drew Falkman [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 4:49 PM
To: JRun-Talk
Subject: RE: Do application variables need locking?


Hey Nick-

In Java, to protect session and application variables from multithreading
issues, you need to use synchronization. A good way to do this is to use
JavaBeans components to store your session and application data. Then within
your bean, you can use the synchronized keyword to synchronize your objects
and methods. For example, if you have a bean called ShoppingCart which
stores a users shopping cart information in an object called cartItems with
an add() method, you could do this:

synchronized (cartItems) {
  cartItems.add(item,price)
}

The key is that you want to synchronize your object when you make changes
(just as you would do with cflock). Beans allows you to do this fairly
easily. Then just store the bean in application or session scope.

-Drew Falkman
Author, JRun Web Application Construction Kit
http://www.drewfalkman.com/books/0789726009/

-----Original Message-----
From: Nick de Voil [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 12, 2002 12:19 PM
To: JRun-Talk
Subject: Do application variables need locking?


In ColdFusion, an application variable needs to be locked while it's being
accessed, to prevent one user writing to it when another is reading,
giving indeterminate results or worse.

Do we need to do something similar with JRun?

I want to keep a set of application parameters in an application object
for reading frequently by many pages, but I also want to have a feature
allowing these parameters to be changed.

Thanks

Nick











______________________________________________________________________
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to