[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r1476359 - in /subversion/trunk/subversion/bindings/javahl/src/org: apache/subversion/javahl/types/LogDate.java tigris/subversion/javahl/LogDate.java

From: Philip Martin <philip.martin_at_wandisco.com>
Date: Mon, 29 Apr 2013 15:44:34 +0100

Mark Phippard <markphip_at_gmail.com> writes:

> On Mon, Apr 29, 2013 at 7:47 AM, Philip Martin
> <philip.martin_at_wandisco.com> wrote:
>> markphip_at_apache.org writes:
>>
>>> Author: markphip
>>> Date: Fri Apr 26 19:48:34 2013
>>> New Revision: 1476359
>>>
>>> URL: http://svn.apache.org/r1476359
>>> Log:
>>> JavaHL: fix a thread safety bug that has been observed in Subclipse.
>>>
>>> The Java SimpleDateFormat class is not thread safe. Solved by
>>> synchronizing the use of the object. Also audited all of our usage of
>>> this class and only this one usage has an issue. There are alternate
>>> implementations we could use, but we would have to copy in the class
>>> to our package. I chose to take the simple approach.
>>
>> Would it be possible to switch to a non-static DateFormat instead?
>
> This would essentially require creating a new object each time the
> method is needed and that would be a lot. My understanding is that
> using synchronize is cheaper in this case.

The org.apache bindings only use LogDate in CommitInfo and I would be
surprised if that was a bottleneck, it simply doesn't get called often
enough.

The legacy org.tigris bindings use LogDate in LogMessageCallback so I
suppose it might be a performance issue there, but only in the
deprecated methods that return an array of log messages. Even then I'd
expect the real overhead to be building the array to hold all log
messages in memory.

The change below appears to have no measureable effect when getting
100,000 log messages over http from localhost (an operation that takes
the Java client 9s CPU, 28s runtime):

Index: ../src/subversion/bindings/javahl/src/org/tigris/subversion/javahl/LogDate.java
===================================================================
--- ../src/subversion/bindings/javahl/src/org/tigris/subversion/javahl/LogDate.java (revision 1476992)
+++ ../src/subversion/bindings/javahl/src/org/tigris/subversion/javahl/LogDate.java (working copy)
@@ -39,8 +39,6 @@
 public class LogDate implements java.io.Serializable
 {
     private static final long serialVersionUID = 1L;
- private static final DateFormat formatter = new SimpleDateFormat(
- "yyyy-MM-dd'T'HH:mm:ss.SSS z");
     private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
 
     private final long timeMicros;
@@ -53,11 +51,8 @@
         {
             throw new ParseException("String is not a valid Subversion date", 0);
         }
- Date date;
- synchronized(formatter)
- {
- date = formatter.parse(datestr.substring(0, 23) + " UTC");
- }
+ DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS z");
+ Date date = formatter.parse(datestr.substring(0, 23) + " UTC");
         this.cachedString = datestr;
         cachedDate = Calendar.getInstance(UTC);
         cachedDate.setTime(date);

-- 
Certified & Supported Apache Subversion Downloads:
http://www.wandisco.com/subversion/download
Received on 2013-04-29 16:45:29 CEST

This is an archived mail posted to the Subversion Dev mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.