Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: DateFormat is not thread safe

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Location
    San Fransisco
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default DateFormat is not thread safe

    Sorry if this is already posted. But this is one important thing to note:
    DateFormat is not thread safe. Using it in two parallel threads cause corruption of data or runtime exception. Use jodatime where ever you can.

    Acumen,
    http://lucid-forums.com


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: DateFormat is not thread safe

    Indeed, this is what the API tells you.

    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.
    I personally like using Joda-Time as well, its great. I believe the current Java API for dates is somewhat behind its time, hehe.

    // Json

  3. #3
    Junior Member
    Join Date
    Aug 2009
    Location
    San Fransisco
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: DateFormat is not thread safe

    Yeah, I agree with that.

    Acumen,
    Lucid forums

  4. #4
    Junior Member
    Join Date
    Aug 2009
    Location
    San Fransisco
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: DateFormat is not thread safe

    I thought this was a tip, just curious why is this moved to 'New to Java'.

    Acumen,
    Lucid forums

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: DateFormat is not thread safe

    Quote Originally Posted by trueacumen View Post
    I thought this was a tip, just curious why is this moved to 'New to Java'.

    Acumen,
    Lucid forums
    Hey trueacumen.

    Sorry I moved this to the 'New to Java' forum as the 'Tips & Tutorials' forum is more for code snippets & examples.

    Thanks for the submission though, I may add a sub forum called 'Tips' for things like this. What do you think?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #6
    Junior Member
    Join Date
    Aug 2009
    Location
    San Fransisco
    Posts
    21
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: DateFormat is not thread safe

    I think that makes sense. I really appreciate the effort you are putting in maintaining these forums.

Similar Threads

  1. wheres the thread about inverted String?
    By chronoz13 in forum Java Theory & Questions
    Replies: 5
    Last Post: July 29th, 2009, 11:13 AM
  2. UDP server sends thread application
    By Koren3 in forum Threads
    Replies: 2
    Last Post: April 20th, 2009, 11:46 AM
  3. [SOLVED] Problem while getting a number from another thread
    By Koren3 in forum Threads
    Replies: 4
    Last Post: April 7th, 2009, 01:42 PM
  4. How to do thread communication in java
    By Koren3 in forum Threads
    Replies: 4
    Last Post: March 29th, 2009, 10:49 AM
  5. Important: Marking your Thread as SOLVED
    By JavaPF in forum Forum Updates & Feedback
    Replies: 0
    Last Post: December 5th, 2008, 09:33 AM

Tags for this Thread