You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Arun Thomas <Ar...@solidusnetworks.com> on 2003/09/10 22:29:55 UTC

MapUtils.debug/verbosePrint thread safety

I recently noticed that the current implementation of the debugPrint and verbosePrint methods in MapUtils is not thread safe - in fact, these are the only items that are not thread safe because the indentation state for the output is preserved in a static variable.  
 
I think it would be fairly simple to make this thread safe, but it would require a change to the signature of a protected member function printIndent(PrintStream out) -> printIndent(PrintStream out, int indentDepth).  I'm not really clear as to why this method is protected rather than private (can anyone clarify?).  Does it need to be protected?  
 
Looking forward to input from others.
-AMT  

Re: [collections] MapUtils.debug/verbosePrint thread safety

Posted by Stephen Colebourne <sc...@btopenworld.com>.
The methods that call this one are synchronized to protect them, so it
should be thread-safe.

However, I would prefer them not to need to be synchronized. If you want to
submit a patch that reworks the methods that would be great.

Incompatable change?
The protected method should remain and be deprecated, as it may be used by a
MapUtils subclass (feasible but unlikely). However, I would prefer just to
go incompatable change on this one. Other committers may differ, but if they
don't I'll just commit the incompatable change.

Stephen

----- Original Message -----
From: "Arun Thomas" <Ar...@solidusnetworks.com>
> I recently noticed that the current implementation of the debugPrint and
verbosePrint methods in MapUtils is not thread safe - in fact, these are the
only items that are not thread safe because the indentation state for the
output is preserved in a static variable.
>
> I think it would be fairly simple to make this thread safe, but it would
require a change to the signature of a protected member function
printIndent(PrintStream out) -> printIndent(PrintStream out, int
indentDepth).  I'm not really clear as to why this method is protected
rather than private (can anyone clarify?).  Does it need to be protected?
>
> Looking forward to input from others.
> -AMT
>


----------------------------------------------------------------------------
----


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [collections] MapUtils.debug/verbosePrint thread safety

Posted by Stephen Colebourne <sc...@btopenworld.com>.
I like the System.out theory. Its probably unintentional, but it true. So
only a documentation patch is required then...:-)
Stephen

----- Original Message -----
From: "Janek Bogucki" <ya...@studylink.com>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Wednesday, September 10, 2003 11:12 PM
Subject: Re: MapUtils.debug/verbosePrint thread safety


> On Wed, 2003-09-10 at 20:29, Arun Thomas wrote:
> > I recently noticed that the current implementation of the debugPrint and
verbosePrint methods in MapUtils is not thread safe - in fact, these are the
only items that are not thread safe because the indentation state for the
output is preserved in a static variable.
> >
> > I think it would be fairly simple to make this thread safe, but it would
require a change to the signature of a protected member function
printIndent(PrintStream out) -> printIndent(PrintStream out, int
indentDepth).  I'm not really clear as to why this method is protected
rather than private (can anyone clarify?).  Does it need to be protected?
> >
> > Looking forward to input from others.
> > -AMT
>
> These methods are synchronized so are currently thread safe.
>
>     public static synchronized void verbosePrint (...)
>
>     public static synchronized void debugPrint (...)
>
> I would guess that a second intentional benefit of the synchronization
> is to prevent overlapping invocations writing to System.out at the same
> time.
>
> -Janek
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>


Re: MapUtils.debug/verbosePrint thread safety

Posted by Janek Bogucki <ya...@studylink.com>.
On Wed, 2003-09-10 at 20:29, Arun Thomas wrote:
> I recently noticed that the current implementation of the debugPrint and verbosePrint methods in MapUtils is not thread safe - in fact, these are the only items that are not thread safe because the indentation state for the output is preserved in a static variable.  
>  
> I think it would be fairly simple to make this thread safe, but it would require a change to the signature of a protected member function printIndent(PrintStream out) -> printIndent(PrintStream out, int indentDepth).  I'm not really clear as to why this method is protected rather than private (can anyone clarify?).  Does it need to be protected?  
>  
> Looking forward to input from others.
> -AMT  

These methods are synchronized so are currently thread safe.

    public static synchronized void verbosePrint (...)

    public static synchronized void debugPrint (...)

I would guess that a second intentional benefit of the synchronization
is to prevent overlapping invocations writing to System.out at the same
time.

-Janek