Return-Path: Delivered-To: apmail-tomcat-users-archive@www.apache.org Received: (qmail 9390 invoked from network); 11 May 2009 13:48:16 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 11 May 2009 13:48:16 -0000 Received: (qmail 26250 invoked by uid 500); 11 May 2009 13:48:11 -0000 Delivered-To: apmail-tomcat-users-archive@tomcat.apache.org Received: (qmail 25773 invoked by uid 500); 11 May 2009 13:48:11 -0000 Mailing-List: contact users-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Users List" Delivered-To: mailing list users@tomcat.apache.org Received: (qmail 25509 invoked by uid 99); 11 May 2009 13:48:10 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 May 2009 13:48:10 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of knst.kolinko@gmail.com designates 209.85.218.177 as permitted sender) Received: from [209.85.218.177] (HELO mail-bw0-f177.google.com) (209.85.218.177) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 May 2009 13:48:02 +0000 Received: by bwz25 with SMTP id 25so2832848bwz.0 for ; Mon, 11 May 2009 06:47:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=3K9elPnVHzj9J4EVT2YTBWXWmPRVM7+ng7CsGukqr2E=; b=cWky0wmaf3RW+hKi5nElg10BzbF7EcQoh+9y+XnIgav5/p1unyS8aQ58mfrw3TeAP4 R0h7sCEpoErkQEkqXA9ZiFkBN+y0Z9XSLUCcnXs6JkfvkG5/IAv27iy3mozLEk0QISi/ GO8xCEvFuBbRDI357JRhxehLsOGtnQccyvPys= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=RL2bRhtfsMtnU/1QoyNl5rB0pYBrqS5uJptMNCfBZ3tyS1RM75KWFkuaPqcwDnGiwC RPSNTKi0Qy5h/2aPxrFCNP1msCV5y2hTi95rnT+7gJbHsLG/8ROU5Q9ZXHMj5DDd5PTZ skaOhIBasp8uAAV3aywxfonUmpI4apyZjW4aY= MIME-Version: 1.0 Received: by 10.103.223.2 with SMTP id a2mr3999845mur.88.1242049661093; Mon, 11 May 2009 06:47:41 -0700 (PDT) In-Reply-To: <4A0827A8.6070103@verizon.net> References: <4A0827A8.6070103@verizon.net> Date: Mon, 11 May 2009 17:47:41 +0400 Message-ID: <427155180905110647p510d4ed3wb07ee0fdee6f494f@mail.gmail.com> Subject: Re: Trouble parsing datetime strings From: Konstantin Kolinko To: Tomcat Users List Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org 2009/5/11 David kerber : > This is related to the performance issues discussed in the thread > "Performance with many small requests". > > When I reworked my servlet to synchronize only on pieces that needed to b= e > synchronized, rather than on the entire request processing routine, I am = now > throwing an exception when parsing a string into a java.util.Date variabl= e. > =A0It only happens occasionally, maybe once every few dozen to a hundred = or so > requests, and I can't figure out why it doesn't work all the time. > > Declared at the class level, I have: > > =A0 private static final SimpleDateFormat =A0 =A0sdfFullDateTime =3D new > SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); > > > Then in the request processing method, I have > > =A0 dateTimeStr =3D dateStr + " " + timeStr; > =A0 try { > =A0 =A0 =A0 dataDate =3D sdfFullDateTime.parse( dateTimeStr ); > =A0 } catch ( Exception e ) { > =A0 =A0 =A0 writeLog( "Unable to parse dataTime string: '", dateTimeStr += "': " + > e ); > =A0 } > > > (the try/catch is there only for debugging this issue), and in the log I'= m > seeing: > > 2009-05-11 09:19:54: Unable to parse dateTime string: ': =A0'2009-05-11 > 09:19:37': java.lang.NumberFormatException: For input string: ""' > > > Which I don't understand at all; dateDate (java.util.Date), dateStr > (String), timeStr (String) and dateTimeStr (String) are all declared in t= he > processing method, NOT at the class level. > > Maybe I should move the declaration of the SimpleDateFormat into the > processing method? =A0Or synchronize the date parse? > > > I'm kind of lost here; any help appreciated!! > > Dave > As the JavaDoc says http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html "Date formats are not synchronized. It is recommended to create separate format instances for each thread" You may either create a new instance of SimpleDateFormat each time, or add a synchronization around that part of code, or use a ThreadLocal (though ThreadLocal has its own caveats as the threads belong to Tomcat and are shared among applications). Without profiling you would not know which one of the ways I am mentioning is faster. Maybe I would start with creating a new instance each time, as GC for short-living objects seems to be cheap in recent JREs. Though without profiling you will not get the numbers. Best regards, Konstantin Kolinko --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org For additional commands, e-mail: users-help@tomcat.apache.org