Last active
October 6, 2017 12:45
-
-
Save vega113/747c15df0859d975ca81 to your computer and use it in GitHub Desktop.
Example of Java 6/7 threaf safety issue with SimpleDateFormat.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.yuri.java8.time; | |
import org.joda.time.format.DateTimeFormat; | |
import org.joda.time.format.DateTimeFormatter; | |
import java.util.concurrent.ExecutorService; | |
import java.util.concurrent.Executors; | |
/** | |
* Created by yuri.zelikov on 1/11/2016. | |
*/ | |
public class JodaDateThreadSafetyExample { | |
private static final DateTimeFormatter sdf = DateTimeFormat.forPattern("HH:mm:ss dd.MM.yyyy"); | |
public static void main(String[] args) { | |
ExecutorService executor = Executors.newFixedThreadPool(100); | |
while (true) { | |
executor.submit((Runnable) JodaDateThreadSafetyExample::workConcurrently); | |
} | |
} | |
public static void workConcurrently() { | |
try { | |
sdf.parseDateTime("19:30:55 03.05.2015"); | |
System.out.print("OK "); | |
} catch (Throwable th) { | |
System.out.println(th.getClass() + " : " + th.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment