In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
How to understand SimpleDateFormat, in view of this problem, this article introduces the corresponding analysis and answers in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Testpublic void testParse () {ExecutorService executorService = Executors.newCachedThreadPool (); List dateStrList = Lists.newArrayList ("2018-04-01 10:00:01", "2018-04-02 11:00:02", "2018-04-03 12:00:03", "2018-04-04 13:00:04", "2018-04-05 14:00:05") / * note that this place is easy to make mistakes! * so SimpleDateFormat objects cannot be shared here! * / SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("yyyy-MM-dd hh:mm:ss"); for (String str: dateStrList) {executorService.execute (()-> {try {simpleDateFormat.parse (str); TimeUnit.SECONDS.sleep (1);} catch (Exception e) {e.printStackTrace ();}}) }
The parse method of using SimpleDateFormat in a concurrent environment has thread safety problems!
Causes of thread safety problems:
If thread An empties the calendar at this time and does not set a new value
Thread B also enters the parse method using the calendar object in the SimpleDateFormat object.
Thread safety problems will arise at this point!
The SimpleDateFormat conversion date is manipulated through the Calendar object
The answer to the question on how to understand SimpleDateFormat is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.