Originally wanted to set a static SimpleDateFormat constant at the top of the class
Public final static DateFormat dateformatgmt = new SimpleDateFormat ("EEE, d MMM yyyy HH:mm:ss z", locale.english);
For use by multiple threads, but after one weeks, two exceptions were found to be thrown this evening.
The number of threads at that time should be around 30.
I always thought it was thread-safe, but today throws this exception:
Exception in Thread "Thread-91" Exception in Thread "Thread-101" Java.lang.ArrayIndexOutOfBoundsException: 2147483648
At Java.text.SimpleDateFormat.subFormat (Unknown Source)
At Java.text.SimpleDateFormat.format (Unknown Source)
At Java.text.SimpleDateFormat.format (Unknown Source)
At Java.text.DateFormat.format (Unknown Source)
At server. Task.run (task.java:362)
I did not know what went wrong, searched for a moment, and found an answer:
The Java.text.SimpleDateFormat class is not thread-safe.
http://www.ibm.com/developerworks/cn/java/j-jtp09263/
Finally, we had to change the code:
Private DateFormat dateformatgmt = new SimpleDateFormat ("EEE, d MMM yyyy HH:mm:ss z", locale.english);
2009-10-15
Calling Simpledateformat.format () in a multithreaded state throws a ArrayIndexOutOfBoundsException exception