Tagged articles
26 articles
Page 1 of 1
Java Backend Technology
Java Backend Technology
Sep 26, 2023 · Backend Development

Why Does Using 'YYYY' in Java Date Formatting Show the Wrong Year?

A Java date‑formatting bug occurs when the week‑based year pattern 'YYYY' is used instead of the calendar year 'yyyy', causing dates near year‑end to display the next year, and this article explains the cause, demonstrates it with code, and shows how to avoid it.

BackendDate FormattingSimpleDateFormat
0 likes · 4 min read
Why Does Using 'YYYY' in Java Date Formatting Show the Wrong Year?
Selected Java Interview Questions
Selected Java Interview Questions
Aug 31, 2023 · Backend Development

How to Solve SimpleDateFormat Thread Safety Issues in High-Concurrency Scenarios

This article presents several common solutions for addressing the thread‑safety problem of Java's SimpleDateFormat in high‑concurrency environments, including using local variables, synchronized blocks, Lock, ThreadLocal, Java 8 DateTimeFormatter, and Joda‑Time, and evaluates their performance and suitability.

DateTimeFormatterJavaSimpleDateFormat
0 likes · 17 min read
How to Solve SimpleDateFormat Thread Safety Issues in High-Concurrency Scenarios
360 Quality & Efficiency
360 Quality & Efficiency
May 19, 2023 · Backend Development

Resolving SimpleDateFormat Thread Safety Issues with ThreadLocal in Java

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the concurrency problem with a multithreaded demo, and presents three solutions—creating new instances, synchronizing access, and using ThreadLocal—highlighting the ThreadLocal approach with code examples and discussion of potential memory‑leak considerations.

SimpleDateFormatThreadLocalconcurrency
0 likes · 4 min read
Resolving SimpleDateFormat Thread Safety Issues with ThreadLocal in Java
Tuanzi Tech Team
Tuanzi Tech Team
Nov 8, 2022 · Backend Development

Why Does SimpleDateFormat Fail in Multithreaded Java? Solutions and Best Practices

An operation team discovered that QR code redirects returned 404 due to expired access tokens, traced to SimpleDateFormat’s thread‑unsafe parsing causing incorrect expiration dates; the article analyzes the root cause, demonstrates failing multithreaded tests, and presents four thread‑safe alternatives including local instances, synchronization, ThreadLocal, and Java 8’s DateTimeFormatter.

DateTimeFormatterJavaSimpleDateFormat
0 likes · 10 min read
Why Does SimpleDateFormat Fail in Multithreaded Java? Solutions and Best Practices
Selected Java Interview Questions
Selected Java Interview Questions
Sep 7, 2022 · Backend Development

Java Date and Time Formatting: Methods, Thread Safety, and Best Practices

This article compares three common Java date‑time formatting approaches—SimpleDateFormat, Java 8’s DateTimeFormatter, and Apache Commons Lang3’s DateFormatUtils—examines thread‑safety issues, provides code examples, and offers conversion utilities between Date, LocalDate, and LocalDateTime for robust backend development.

Apache CommonsDateTimeFormatterSimpleDateFormat
0 likes · 9 min read
Java Date and Time Formatting: Methods, Thread Safety, and Best Practices
Java Backend Technology
Java Backend Technology
Aug 26, 2022 · Fundamentals

10 Common Java Date API Pitfalls and How to Avoid Them

This article lists ten frequent mistakes when using Java's date and time APIs—such as misusing Calendar fields, wrong format patterns, thread‑unsafe SimpleDateFormat, and daylight‑saving quirks—and provides clear corrected examples and best‑practice solutions.

CalendarSimpleDateFormatTimezone
0 likes · 12 min read
10 Common Java Date API Pitfalls and How to Avoid Them
Java Architect Essentials
Java Architect Essentials
Jul 3, 2022 · Backend Development

Thread Safety Issues of SimpleDateFormat.parse() and format() Methods and Their Solutions

This article explains why SimpleDateFormat.parse() and SimpleDateFormat.format() are not thread‑safe in Java, analyzes the underlying causes involving shared Calendar objects, and presents three practical solutions—including per‑thread instances, synchronized blocks, and ThreadLocal usage—to eliminate concurrency bugs.

Date ParsingSimpleDateFormatSynchronization
0 likes · 11 min read
Thread Safety Issues of SimpleDateFormat.parse() and format() Methods and Their Solutions
Programmer DD
Programmer DD
Dec 26, 2021 · Backend Development

Why 'YYYY-MM-dd' Gives the Wrong Year in Java – The Week‑Based Year Pitfall

The article explains why using the pattern 'YYYY‑MM‑dd' with Java's SimpleDateFormat can produce an incorrect year for dates near the end of the year, demonstrates the issue with a unit test comparing it to the correct 'yyyy‑MM‑dd' pattern, and reveals that the problem stems from the week‑based year semantics of 'Y'.

Date FormattingJavaSimpleDateFormat
0 likes · 5 min read
Why 'YYYY-MM-dd' Gives the Wrong Year in Java – The Week‑Based Year Pitfall
Full-Stack Internet Architecture
Full-Stack Internet Architecture
May 18, 2021 · Backend Development

Understanding Thread Safety Issues with SimpleDateFormat and Solutions in Java

This article explains why SimpleDateFormat is not thread‑safe in Java, demonstrates the problem with multithreaded examples, and presents five practical solutions—including local variables, synchronized blocks, explicit locks, ThreadLocal, and the modern DateTimeFormatter—along with their advantages and drawbacks.

DateTimeFormatterJavaSimpleDateFormat
0 likes · 13 min read
Understanding Thread Safety Issues with SimpleDateFormat and Solutions in Java
Programmer DD
Programmer DD
Dec 30, 2020 · Backend Development

Why Using YYYY‑MM‑dd Can Produce Wrong Years in Java Date Formatting

This article demonstrates how the week‑based year pattern "YYYY" in Java's SimpleDateFormat can incorrectly roll over the year for dates near year‑end, provides a reproducible unit test with code and output, and explains the underlying reason behind the discrepancy.

Date FormattingSimpleDateFormatweek-based-year
0 likes · 4 min read
Why Using YYYY‑MM‑dd Can Produce Wrong Years in Java Date Formatting
Java Architecture Diary
Java Architecture Diary
Nov 2, 2019 · Backend Development

Why SimpleDateFormat Is Not Thread‑Safe and How to Fix It Efficiently

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the resulting concurrency errors, and presents four practical solutions—including per‑call instantiation, ThreadLocal, Apache FastDateFormat, and Java 8's Instant with DateTimeFormatter—along with JMH benchmark results comparing their performance across JDK 8 and JDK 11.

SimpleDateFormatThreadLocaldateformat
0 likes · 7 min read
Why SimpleDateFormat Is Not Thread‑Safe and How to Fix It Efficiently
Programmer DD
Programmer DD
Aug 25, 2019 · Backend Development

Why SimpleDateFormat Fails in Multithreaded Java and How to Fix It

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the problem with multithreaded examples, and presents two robust solutions—using ThreadLocal or the Java 8 immutable date‑time API—to ensure correct date formatting in concurrent environments.

SimpleDateFormatdate-time-apijava-8
0 likes · 6 min read
Why SimpleDateFormat Fails in Multithreaded Java and How to Fix It
Programmer DD
Programmer DD
May 12, 2019 · Backend Development

Why SimpleDateFormat Breaks in Multithreaded Java and How to Fix It

This article explains why the classic Java SimpleDateFormat class is not thread‑safe, demonstrates the problems caused by using a static instance in concurrent code, and presents four practical solutions—including creating new instances, synchronizing, using ThreadLocal, and switching to the immutable DateTimeFormatter.

DateTimeFormatterJavaSimpleDateFormat
0 likes · 8 min read
Why SimpleDateFormat Breaks in Multithreaded Java and How to Fix It
Java Backend Technology
Java Backend Technology
Mar 19, 2019 · Backend Development

Why SimpleDateFormat Is Not Thread‑Safe and How to Fix It in Java

This article explains why Java's SimpleDateFormat is not thread‑safe, demonstrates the problems caused by using a static instance in multithreaded code, and presents four practical solutions—including synchronized blocks, ThreadLocal, and the modern DateTimeFormatter—to ensure correct date handling.

DateTimeFormatterJavaSimpleDateFormat
0 likes · 5 min read
Why SimpleDateFormat Is Not Thread‑Safe and How to Fix It in Java
Qunar Tech Salon
Qunar Tech Salon
Mar 13, 2016 · Fundamentals

Understanding java.util.Date, Calendar, and SimpleDateFormat in Java

This article explains the legacy java.util.Date class, its limited useful constructors and methods, the more flexible java.util.Calendar API, how to format and parse dates with DateFormat and SimpleDateFormat, and best practices for storing timestamps in databases using long values.

CalendarSimpleDateFormatdatabase
0 likes · 9 min read
Understanding java.util.Date, Calendar, and SimpleDateFormat in Java