15
15
*/
16
16
package org .beanio .types ;
17
17
18
- import java .text .*;
19
- import java .util .*;
18
+ import java .text .DateFormat ;
19
+ import java .text .ParsePosition ;
20
+ import java .text .SimpleDateFormat ;
21
+ import java .util .Date ;
22
+ import java .util .Properties ;
23
+ import java .util .TimeZone ;
20
24
21
25
/**
22
26
* This abstract type handler uses a <tt>SimpleDateFormat</tt> class to parse and format
@@ -38,7 +42,7 @@ public abstract class DateTypeHandlerSupport extends LocaleSupport implements Co
38
42
// the same format instance can be reused if this type handler is not shared
39
43
// by multiple unmarshallers/marshallers, this can lead to significant
40
44
// performance improvements when parsing many records
41
- private transient DateFormat format ;
45
+ private transient ThreadLocal < DateFormat > format = new ThreadLocal <>() ;
42
46
43
47
/**
44
48
* Constructs a new AbstractDateTypeHandler.
@@ -81,7 +85,7 @@ protected String formatDate(Date date) {
81
85
}
82
86
83
87
private DateFormat getFormat () {
84
- return this .format != null ? this .format : createDateFormat ();
88
+ return this .format . get () != null ? this .format . get () : createDateFormat ();
85
89
}
86
90
87
91
/**
@@ -128,7 +132,8 @@ public DateTypeHandlerSupport newInstance(Properties properties) throws IllegalA
128
132
handler .setPattern (pattern );
129
133
handler .lenient = this .lenient ;
130
134
handler .timeZone = this .timeZone ;
131
- handler .format = handler .createDateFormat ();
135
+ handler .format = new ThreadLocal <>();
136
+ handler .format .set (handler .createDateFormat ());
132
137
return handler ;
133
138
}
134
139
catch (CloneNotSupportedException e ) {
0 commit comments