线程安全的 SimpleDateFormat
来源:互联网 发布:进存销软件哪些免费 编辑:程序博客网 时间:2024/05/16 15:03
- import java.text.SimpleDateFormat;
- import java.util.HashMap;
- import java.util.Map;
- public class DateFormatFactory {
- private static final Map<String, ThreadLocal<SimpleDateFormat>> pool = new HashMap<String, ThreadLocal<SimpleDateFormat>>();
- private static final Object lock = new Object();
- public static SimpleDateFormat getDateFormat(String pattern) {
- ThreadLocal<SimpleDateFormat> tl = pool.get(pattern);
- if (tl == null) {
- synchronized (lock) {
- tl = pool.get(pattern);
- if (tl == null) {
- final String p = pattern;
- tl = new ThreadLocal<SimpleDateFormat>() {
- protected synchronized SimpleDateFormat initialValue() {
- return new SimpleDateFormat(p);
- }
- };
- pool.put(p, tl);
- }
- }
- }
- return tl.get();
- }
- }
- public static Date toDate(String dateStr,String pattern) {
- try{
- return getDateFormat(pattern).parse(dateStr);
- }catch (ParseException e) {
- }
- return null;
- }
阅读全文
0 0
- 线程安全的 SimpleDateFormat
- SimpleDateFormat线程安全的问题
- SimpleDateFormat 为什么不是线程安全的
- 非线程安全类SimpleDateFormat的禁忌
- SimpleDateFormat不是线程安全的类
- SimpleDateFormat 线程安全的解决方案--DateTimeFormatter
- 为什么SimpleDateFormat不是线程安全的?
- SimpleDateFormat的线程安全和ThreadLocal
- SimpleDateFormat非线程安全
- SimpleDateFormat非线程安全
- SimpleDateFormat 转为线程安全
- SimpleDateFormat 非线程安全
- 线程安全之SimpleDateFormat
- SimpleDateFormat线程安全
- SimpleDateFormat非线程安全
- java SimpleDateFormat线程安全
- SimpleDateFormat非线程安全
- SimpleDateFormat 解决非线程安全
- 渣打银行、阿联酋RAK银行分别借助瑞波技术实现对印度的实时跨境支付
- 菲律宾监管机构考虑发布比特币交易所和ICO监管规则
- 【免费报名】ConsenSys开发者工具核心团队首次亮相中国:如何构建高质量的以太坊DApp?
- 【转】(二)零基础写Java知乎爬虫之进阶篇
- 白俄罗斯或明确比特币的合法地位,允许交易所运营
- 线程安全的 SimpleDateFormat
- 小公司程序员怎么进大公司
- mysql数据库函数
- 解决cocoapods diff: /../Podfile.lock: No such file or directory
- 解决SettingsProvider中的值读写不同步的问题
- 优达(Udacity)-机器学习基础-异常值
- Jamie Dimon回来了!摩根大通考虑比特币期货
- 马来西亚央行规划加密货币报告规定
- C++的由来