how to create a thread local variable in java
public class MyDateFormatter {
private ThreadLocal<SimpleDateFormat> simpleDateFormatThreadLocal = new ThreadLocal<>();
public String format(Date date) {
SimpleDateFormat simpleDateFormat = getThreadLocalSimpleDateFormat();
return simpleDateFormat.format(date);
}
private SimpleDateFormat getThreadLocalSimpleDateFormat() {
SimpleDateFormat simpleDateFormat = simpleDateFormatThreadLocal.get();
if(simpleDateFormat == null) {
simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormatThreadLocal.set(simpleDateFormat);
}
return simpleDateFormat;
}
}
Also in Java:
- how to install java 8 on terminal os
- when super add by constructor in java
- java string to boolean
- processing library cassette
- select photo from camera android
- how to make an object move with arrow keys in java
- boolean parse jtextfield
- java code to save excel data to mysql
- how to declare array java
- javafx textarea how to make smaller
- spigot get player from UUID
- entre clavier java
- fragment button nullpointerexception
- android java convert double to 2 decimal places
- indexof java
- javafx action event enter key
- how to scan a character in java
- how to remove a certain string in a arraylist java
- action on long press of edit edittext
- java how to make a gui
- create java windows application
- how to create a button in java
- expression régulière seulement un espace java
- java iterator example