Uploaded image for project: 'DSpace'
  1. DSpace
  2. DS-594

DCDate parsing thread synchronization issue

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed (View Workflow)
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 1.6.1
    • Fix Version/s: 1.7.0
    • Component/s: DSpace API
    • Labels:
      None
    • Attachments:
      2
    • Comments:
      6
    • Documentation Status:
      Not Required

      Description

      I have been getting a variety of exceptions coming from org.dspace.content.DCDate that look suspiciously like SimpleDateFormat thread synchronization issues (such as "java.lang.NumberFormatException: multiple points"). On closer inspection I noticed that the DCDate(String) constructor is calling the 'tryParse' method which is not 'static' synchronized and thus the locking is based on the DCDate instance itself and not the class. As such the 'synchronized' keyword on tryParse is redundent since that method is only called by the constructor (a time when no other code can get a lock on the DCDate instance).

      The fix would be to either add the 'static' keyword to tryParse, which would be a fairly major performance bottleneck, or to simply clone the SimpleDateFormat instance and use that to parse the string. Example code:

      private static Date tryParse(SimpleDateFormat sdf, String source)
      {
      try

      { SimpleDateFormat clone = (SimpleDateFormat) sdf.clone(); return clone.parse(source); }

      catch (ParseException pe)

      { return null; }

      }

        Attachments

        1. DCDateConcurrencyTest.java
          1 kB
          Andrew Taylor
        2. DS-594.diff
          0.7 kB
          Andrew Taylor

          Activity

            People

            • Assignee:
              robintaylor Robin Taylor
              Reporter:
              ataylor Andrew Taylor
            • Votes:
              1 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: