You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Klotz Jr, Dennis" <DK...@empirix.com> on 2006/03/14 19:57:24 UTC
Concurrency question for servlets
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: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Concurrency question for servlets
Posted by Leon Rosenberg <ro...@googlemail.com>.
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 <DK...@empirix.com> 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: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org