Commit 6fe42a2e0a9a7ad12dbd3edae83fb2e09214adb1
1 parent
02ac176821
Exists in
master
and in
6 other branches
update code
Showing 1 changed file with 50 additions and 50 deletions
platform-msg-generate/src/main/java/com/lyms/platform/msg/utils/DateUtils.java
View file @
6fe42a2
... | ... | @@ -31,70 +31,70 @@ |
31 | 31 | public static final String Y_M_D_H_M_S = "yyyy-MM-dd HH:mm:ss"; |
32 | 32 | public static final String Y_M_D_H_M = "yyyy-MM-dd HH:mm"; |
33 | 33 | |
34 | -// private static Map<String, ThreadLocal<SimpleDateFormat>> formatMap = new HashMap<String, ThreadLocal<SimpleDateFormat>>(); | |
34 | + private static Map<String, ThreadLocal<SimpleDateFormat>> formatMap = new HashMap<String, ThreadLocal<SimpleDateFormat>>(); | |
35 | 35 | |
36 | - private static ThreadLocal<SimpleDateFormat> threadLocal = new ThreadLocal<SimpleDateFormat>(){ | |
37 | - @Override | |
38 | - protected SimpleDateFormat initialValue() { | |
39 | - return new SimpleDateFormat(Y_M_D_H_M_S); | |
40 | - } | |
41 | - }; | |
36 | +// private static ThreadLocal<SimpleDateFormat> threadLocal = new ThreadLocal<SimpleDateFormat>(){ | |
37 | +// @Override | |
38 | +// protected SimpleDateFormat initialValue() { | |
39 | +// return new SimpleDateFormat(Y_M_D_H_M_S); | |
40 | +// } | |
41 | +// }; | |
42 | 42 | |
43 | 43 | private static final String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"}; |
44 | 44 | |
45 | 45 | |
46 | - /** | |
47 | - * 为每个线程创建一个时间格式化实例 | |
48 | - * @param dateFormat | |
49 | - * @return | |
50 | - */ | |
51 | - private static SimpleDateFormat getDateFormat(String dateFormat) | |
52 | - { | |
53 | - SimpleDateFormat simpleDateFormat = threadLocal.get(); | |
54 | - if (simpleDateFormat == null) | |
55 | - { | |
56 | - simpleDateFormat = new SimpleDateFormat(dateFormat); | |
57 | - threadLocal.set(simpleDateFormat); | |
58 | - } | |
59 | - simpleDateFormat.applyPattern(dateFormat); | |
60 | - return simpleDateFormat; | |
61 | - } | |
62 | - | |
63 | - | |
64 | 46 | // /** |
65 | 47 | // * 为每个线程创建一个时间格式化实例 |
66 | 48 | // * @param dateFormat |
67 | 49 | // * @return |
68 | 50 | // */ |
69 | -// private static SimpleDateFormat getDateFormat(final String dateFormat) | |
51 | +// private static SimpleDateFormat getDateFormat(String dateFormat) | |
70 | 52 | // { |
71 | -// try { | |
72 | -// ThreadLocal<SimpleDateFormat> tl = formatMap.get(dateFormat); | |
73 | -// if (tl == null) | |
74 | -// { | |
75 | -// lock.lock(); | |
76 | -// tl = formatMap.get(dateFormat); | |
77 | -// if (tl == null) | |
78 | -// { | |
79 | -// tl = new ThreadLocal<SimpleDateFormat>() | |
80 | -// { | |
81 | -// @Override | |
82 | -// protected SimpleDateFormat initialValue() | |
83 | -// { | |
84 | -// return new SimpleDateFormat(dateFormat); | |
85 | -// } | |
86 | -// }; | |
87 | -// formatMap.put(dateFormat, tl); | |
88 | -// } | |
89 | -// } | |
90 | -// return tl.get(); | |
91 | -// } | |
92 | -// finally | |
53 | +// SimpleDateFormat simpleDateFormat = threadLocal.get(); | |
54 | +// if (simpleDateFormat == null) | |
93 | 55 | // { |
94 | -// lock.unlock(); | |
56 | +// simpleDateFormat = new SimpleDateFormat(dateFormat); | |
57 | +// threadLocal.set(simpleDateFormat); | |
95 | 58 | // } |
96 | -// | |
59 | +// simpleDateFormat.applyPattern(dateFormat); | |
60 | +// return simpleDateFormat; | |
97 | 61 | // } |
62 | + | |
63 | + | |
64 | + /** | |
65 | + * 为每个线程创建一个时间格式化实例 | |
66 | + * @param dateFormat | |
67 | + * @return | |
68 | + */ | |
69 | + private static SimpleDateFormat getDateFormat(final String dateFormat) | |
70 | + { | |
71 | + try { | |
72 | + ThreadLocal<SimpleDateFormat> tl = formatMap.get(dateFormat); | |
73 | + if (tl == null) | |
74 | + { | |
75 | + lock.lock(); | |
76 | + tl = formatMap.get(dateFormat); | |
77 | + if (tl == null) | |
78 | + { | |
79 | + tl = new ThreadLocal<SimpleDateFormat>() | |
80 | + { | |
81 | + @Override | |
82 | + protected SimpleDateFormat initialValue() | |
83 | + { | |
84 | + return new SimpleDateFormat(dateFormat); | |
85 | + } | |
86 | + }; | |
87 | + formatMap.put(dateFormat, tl); | |
88 | + } | |
89 | + } | |
90 | + return tl.get(); | |
91 | + } | |
92 | + finally | |
93 | + { | |
94 | + lock.unlock(); | |
95 | + } | |
96 | + | |
97 | + } | |
98 | 98 | |
99 | 99 | /** |
100 | 100 | * 获取当前日期是星期几<br> |