SimpleDateFormat
In JavaVery common and used to format date to string and parse string into date in Java but it can cause very subtle and hard to Debug issues if not used carefully because DateFormat and SimpleDateFormat both is not thread-safe and buggy. Call to Format () and parse () method mutate state of DateFormat class and should is synchronized externally in order to AVO ID any issue. Here is few points which you should take care while using SimpleDateFormat in Java:
SimpleDateFormat in Java are not Thread-safe1) Use local dateformat or simpledateformat objects to converting or formatting dates in Java. Making them local ensure that they is not being shared between multiple threads. 2) If you are sharing date& Nbsp;for simpledateformat class in Java and need to externally synchronizecall To format () and parse () method as they mutate state of dateformat object and can create subtle and hardto fix bugs WH Ile formatting Strings or creating dates in Java. Best are to avoid sharing of dateformat class altogether. 3) If you have option Use joda date Time Libr Ary for your date and time related operation. Its easy-to-understand and portable with Java Date API and solves all thread-safety issues associated with Simpledateformat in java. 4) Another good alternative of simpledateformat in Java is Apaches ' commons.lang package which hold a class called fastdateformat utility class and Thread-safe alternative of simpledateformat in Java. 5) Another approach of Synchronizing dateformat and simpledateformat is using ThreadLocal, which Create simpledateformat on per Thread basis but it can be source of severe memory leak and Java.lang.OutOfM Emoryerror if not used carefully. So avoid until you don ' t has any other option. that's all on
SimpleDateFormat
In Java. Many people has pointed off flaw on design of Format class but unfortunately Sun or Oracle have not addressed them in any R Elease not even in JDK7. SimpleDateFormat is still first choice because of it availability on the standard library but should be used carefully.
Read MORE:HTTP://JAVAREVISITED.BLOGSPOT.COM/2012/03/SIMPLEDATEFORMAT-IN-JAVA-IS-NOT-THREAD.HTML#IXZZ3QDZXPBBQ
SimpleDateFormat in Java isn't thread-safe use carefully