Hello, "Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally." This is from the reference of JDK API.
2009/5/11 David kerber <dcker...@verizon.net> > 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 be > synchronized, rather than on the entire request processing routine, I am now > throwing an exception when parsing a string into a java.util.Date variable. > It 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: > > private static final SimpleDateFormat sdfFullDateTime = new > SimpleDateFormat( "yyyy-MM-dd HH:mm:ss" ); > > > Then in the request processing method, I have > > dateTimeStr = dateStr + " " + timeStr; > try { > dataDate = sdfFullDateTime.parse( dateTimeStr ); > } catch ( Exception e ) { > writeLog( "Unable to parse dataTime string: '", dateTimeStr + "': " + > e ); > } > > > (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: ': '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 the > processing method, NOT at the class level. > > Maybe I should move the declaration of the SimpleDateFormat into the > processing method? Or synchronize the date parse? > > > I'm kind of lost here; any help appreciated!! > > Dave > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org > For additional commands, e-mail: users-h...@tomcat.apache.org > > -- Sincerely yours and Best Regards, Xie Xiaodong