piotrl / jvm-simpledateformat

Goal: Create thread safe instance of SimpleDateFormat

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

JVM SimpleDateFormat Kata

Challange

  • Make SimpleDateFormat produce wrong results on multiple threads
  • Create Thread safe SimpleDateFormat

HowTo run

mvn exec:java

Results

SimpleDateFormat without thrad safe checks
[ERROR] SimpleDateFormat thrown exception: java.util.concurrent.ExecutionException: java.lang.NumberFormatException: multiple points

ThreadSafe formatter
[OK] All dates are the same

Solution

  • Creating ThreadLocal instance with SimpleDateFormat
ThreadLocal<DateFormat> threadDateFormat = ThreadLocal.withInitial(() -> new SimpleDateFormat(pattern));

About

Goal: Create thread safe instance of SimpleDateFormat


Languages

Language:Java 100.0%