io.fair_acc.sample.financial.service.ConcurrentDateFormatAccess Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of samples Show documentation
Show all versions of samples Show documentation
Small sample applications to showcase the features of the chart-fx library.
The newest version!
package io.fair_acc.sample.financial.service;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
/**
* @see SimpleDateFormat is not thread safe. For parallel processing of data streams is necessary to use threadlocal processing.
*/
public class ConcurrentDateFormatAccess {
private final String simpleDateFormatString;
public ConcurrentDateFormatAccess(String dateFormatMask) {
simpleDateFormatString = dateFormatMask;
}
public ConcurrentDateFormatAccess() {
simpleDateFormatString = "MM/dd/yyyy";
}
private final ThreadLocal df = new ThreadLocal<>() {
@Override
public DateFormat get() {
return super.get();
}
@Override
protected DateFormat initialValue() {
return new SimpleDateFormat(simpleDateFormatString);
}
@Override
public void remove() {
super.remove();
}
@Override
public void set(DateFormat value) {
super.set(value);
}
};
public Date parse(String dateString) throws ParseException {
return df.get().parse(dateString);
}
public String format(Date date) {
return df.get().format(date);
}
}