当前位置:网站首页>About the program error caused by dateutil time tool class
About the program error caused by dateutil time tool class
2022-04-23 22:06:00 【Live healthy and safe】
One Problem description
DateUtils In the tool class , Call the format date class in the method SimpleDateFormat and calendar Are defined as static member variables . As shown in the figure below :
Define a thread pool , simulation 10 Threads are concurrent , Call this tool class : Different sub threads call different months , can To see 202209 and 202210 The results returned in two months are the same , Data dislocation , Chaos . should 2022209 The last day of the month is :Mon Sep 31 23:59:59 CST 2022.
Two The solution to the problem
- terms of settlement : take DateUtils In the tool class , Retrieval method in Format date class SimpleDateFormat and calendar Are defined as local variables .
After many executions , The input results are correct !
3、 ... and Conclusion
DateUtils The tool class defines global static Calendar class And formatting date classes SimpleDateFormat class , And the... Is used directly within the method calendar Class set、get A series of operations And direct use SimpleDateFormat class Format date . When multiple concurrent requests are being executed , Request to read and write the same calendar and SimpleDateFormat class , Cause each thread to be in getTime You can't get the right time when And program error reporting .
Need to be in DateUtils Class , In the method used by Redefining a Calendar class and new One Format date class SimpleDateFormat class The object of . namely Change the global variables to these two local variables .
版权声明
本文为[Live healthy and safe]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/113/202204232159177562.html
边栏推荐
- 轻量化项目管理思路
- Beijialai touch screen maintenance 4pp065 0571-X74F
- Strictly, severely and quickly strengthen food safety supervision during the epidemic in Shanghai
- Mobile phone uses SSH to log in nanopi M1 summary (this time on the same LAN)
- 通过OpenFeign传递对象类型参数
- Common implementation schemes of delay message
- Implementation of service fusing
- consul 开启健康监控检查
- April 24, 2022 Daily: current progress and open challenges of applying deep learning in the field of Bioscience
- Handling of alternative solutions for openfeign integration with hystrix
猜你喜欢
Hystrix组件
Online Excel to CSV tool
Subcontracting of wechat applet based on uni app
[leetcode refers to offer 18. Delete the node of the linked list (simple)]
Database experiment VI integrity language experiment
Maintenance of coherent PMB power supply of rofin laser hpc840
服务间通信和RestTemplate完成服务间通信
C language programming based on loop structure (PTA)
Common implementation schemes of delay message
Ribbon负载均衡策略
随机推荐
Mobile phone uses SSH to log in nanopi M1 summary (this time on the same LAN)
Resolve the "chromedriver executable needs to be in path" error
手撕《Google SRE Book》
Mixed use of Oracle column row conversion and comma truncated string
NVM introduction, NVM download, installation and use (node version management)
轻量化项目管理思路
[leetcode refers to offer 18. Delete the node of the linked list (simple)]
[leetcode sword finger offer 58 - I. flip word order (simple)]
[leetcode sword finger offer 10 - II. Frog jumping steps (simple)]
A method of asynchronous response of application service through load balancing
服务熔断的实现
SSH in win10
Database Experiment 7 stored procedure experiment
2. GPIO control summary (kernel driver) of nanopi M1 (Quanzhi H3)
[leetcode refers to offer 52. The first common node of two linked lists (simple)]
Pytorch deep learning practice (2)
MySQL back to table
Pytorch installation link sharing
三、zygote启动流程
Beijialai touch screen maintenance 4pp065 0571-X74F