The first implementation of a number formatting library showed some inconsistencies.
Somehow, sometimes, the formatted number was simply wrong.
I never investigated why: it happened either with 1.2.2 and 1.3.
I always suspected that NumberFormat wasn't thread safe.
I simply replaced NumberFormat with my own version
without synchronizing the library method.
Now formatting works without problems.
Hope this helps,
Marco
----- Original Message -----
From: "Peters, Jim"
Subject: Utility class and multi-threaded servlets
> I searched the archives for an answer to my question, but did not see one
> posed exactly like mine.
>
> I am developing a multi-threaded servlet app, and have developed a utility
> class (all static methods) that all the servlets use.
> For example:
>
> public class Utility
> {
> public static String convertDouble(double val)
> {
> NumberFormat nf = NumberFormat.getInstance();
> nf.setMaximumFractionDigits(2);
> nf.setMinimumFractionDigits(2);
> return nf.format(val);
> }
> }
>
> The above is used in my servlets by invoking the method in this manner:
>
> String str = Utility.convertDouble(setUp);
>
> My question is this ... Do I have to synchronize the static methods in my
> Utility class ? Will one thread stomp on another one in the event that
> multiple are executing the code at the same time ?
>
> I suspect the answer is yes but I am also worried about all the threads
> waiting for synchronized methods.
>
> Thanks in advance and I apologize if this is too basic for this forum ...
> maybe I'm brain dead today.
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html