Results 1 to 2 of 2

Thread: DefaultFieldSet: Thread Safety

  1. #1
    Join Date
    Nov 2012
    Posts
    2

    Default DefaultFieldSet: Thread Safety

    Hi,

    When working on a spring batch based application, I encountered an error related to SimpleDateFormat.

    After some investigation, the cause of the error was related to the un-synchronized use of SimpleDateFormat in org.springframework.batch.item.file.transform.Defa ultFieldSet.

    Possible solution: create a new instance of SimpleDateFormat in each method that reads a date field.

    Example:

    Code:
    public Date readDate(int index) {
                    DateFormat dateFormat = new SimpleDateFormat(DEFAULT_DATE_PATTERN);
    		return parseDate(readAndTrim(index), dateFormat);
    	}
    Thanks

  2. #2
    Join Date
    Sep 2008
    Location
    Chicagoland, IL
    Posts
    366

    Default

    Good catch. A quick look through the code shows that we're making the same mistake with NumberFormat. I've opened a Jira issue to track this going forward: https://jira.springsource.org/browse/BATCH-1932
    Michael Minella
    Spring Batch Lead
    Author - Pro Spring Batch
    http://www.michaelminella.com
    Twitter: @MichaelMinella

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •