Hi,

from the tomcat source

package org.apache.catalina.core;

public class ApplicationContext
    implements ServletContext {

....

    public Object getAttribute(String name) {

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

    }


to answer your question:
> Question:
>
> Do I need to put the getServletContext().getAttribute() inside of a
> synchronized (this) block? I am thinking I do.
>

nope :-) It's already synchronized.

Leon

Btw, why should concurrency issues produce a memory leak? A dead lock
or an infinite loop -> absolutely, but memory leaks? Would be first
time I met this issue, but you're never too old to learn :-)

On 3/14/06, Klotz Jr, Dennis <[EMAIL PROTECTED]> wrote:
> Hello.
>
> I hope everyone is having a great day! I hope you have a moment for a
> quick question.
>
> I am fighting a memory leak problem and I want to try and rule in or out
> concurrency issues. So given:
>
> Servlet Code:
>
> -----
>
> public enum XMSContextAttributes { applicationContext };
>
> public void doGet (HttpServletRequest req, HttpServletResponse res)
> throws ServletException, IOException
> {
>     HXMSApplicationContext applicationContext;
>
>     applicationContext = getServletContext ().getAttribute
> (XMSContextAttributes.applicationContext.name ());
>
> ...do something useful here...
> }
>
> -----
>
> Notes:
>
> The applicationContext object is being created by a
> ServletContextListener, and it contains two important ConcurrentHashMap
> objects.
>
> But the applicationContext object itself has no concurrency
> protection... I access it inside of the doGet of certain servlets...
>
> Question:
>
> Do I need to put the getServletContext().getAttribute() inside of a
> synchronized (this) block? I am thinking I do.
>
> Thank you.
>
> -Dennis Klotz
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to