Skip to content

Instantly share code, notes, and snippets.

@ghusta
Last active November 24, 2016 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghusta/6a160e0ae6e0e57a7061960f65fdc438 to your computer and use it in GitHub Desktop.
Save ghusta/6a160e0ae6e0e57a7061960f65fdc438 to your computer and use it in GitHub Desktop.
SimpleDateFormat is not thread-safe, so give one to each thread [Java]
// SimpleDateFormat is not thread-safe, so give one to each thread
private static final ThreadLocal<SimpleDateFormat> DATE_FORMAT_ISO_DATE = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyy-MM-dd"); //$NON-NLS-1$
}
};
@ghusta
Copy link
Author

ghusta commented Nov 24, 2016

Then access by :
DATE_FORMAT_ISO_DATE.get()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment