当前位置:网站首页>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
边栏推荐
- Ribbon 服务调用
- C reads excel specific data into specific columns of DataGridView
- [※ leetcode refers to offer 46. Translate numbers into strings (medium)]
- A solution of C batch query
- Ali has another "against the sky" container framework! This kubernetes advanced manual is too complete
- Opening conditions and process of hystrix circuit breaker and default alternative treatment
- LabVIEW modify the appearance of the application window
- 不同注册中心区别
- April 24, 2022 Daily: current progress and open challenges of applying deep learning in the field of Bioscience
- 从严从重从快 上海全面加强疫情期间食品安全监管
猜你喜欢

Hystrix断路器开启条件和流程以及默认备选处理

consul 关闭健康监控检查
![[leetcode refers to offer 22. The penultimate node in the linked list (simple)]](/img/f1/4d5a3552d1c09d2dfa81e0cfc1547e.png)
[leetcode refers to offer 22. The penultimate node in the linked list (simple)]

服务间通信和RestTemplate完成服务间通信

Handling of alternative solutions for openfeign integration with hystrix

在线Excel转CSV工具

C winfrom DataGridView click on the column header can not automatically sort the problem

Hirschmann display maintenance computer controller repair

Database Experiment 8 trigger experiment

C reads excel specific data into specific columns of DataGridView
随机推荐
Cancel the default open project setting of idea
C reads excel specific data into specific columns of DataGridView
Hirschmann display maintenance computer controller repair
[leetcode refers to offer 10 - I. Fibonacci sequence (simple)]
MySQL 回表
JUnit unit test ---- a good tool for testing a single method
MVC three-tier architecture (illustration)
Online Excel to CSV tool
QT QML component library records owned by QML except basic components
Ali has another "against the sky" container framework! This kubernetes advanced manual is too complete
LabVIEW设置应用程序显示标签透明
Daily operation and maintenance knowledge -- 1
[leetcode sword finger offer 58 - I. flip word order (simple)]
阿里又一个“逆天”容器框架!这本Kubernetes进阶手册简直太全了
Beijialai touch screen maintenance 4pp065 0571-X74F
[leetcode refers to offer 47. Maximum value of gift (medium)]
手撕《Google SRE Book》
Opening conditions and process of hystrix circuit breaker and default alternative treatment
Ribbon停止维护
世界读书日,腾讯安全推荐一份充电书单