package threadLocal; import java.text.DateFormat; import
java.text.ParseException; import java.text.SimpleDateFormat; import
java.util.Date; /** * ThreadLocal usage method 1 * * @author mxp * */ public class
MyThreadLocal { private static ThreadLocal<SimpleDateFormat> threadLocal = new
ThreadLocal<SimpleDateFormat>() { @Override protected SimpleDateFormat
initialValue() { return new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); } };
public static Date parse(String dateStr) throws ParseException { return
threadLocal.get().parse(dateStr); } public static String format(Date date) {
return threadLocal.get().format(date); } } /** * ThreadLocal usage method 2 * * @author
mxp * */ class MythreadLocal2 { private static ThreadLocal<DateFormat> local =
new ThreadLocal<DateFormat>(); private static DateFormat initValue() {
DateFormat dateFormat = local.get(); if (dateFormat == null) { dateFormat = new
SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); local.set(dateFormat); } return
dateFormat; } public static Date parse(String dateStr) throws ParseException {
return initValue().parse(dateStr); } public static String format(Date date) {
return initValue().format(date); } }

Technology
©2019-2020 Toolsou All rights reserved,
The 11th Blue Bridge Cup python The real topic of the University Group National Games JavaSwing To achieve a simple Lianliankan games 【Spring Source code analysis 】42-@Conditional Detailed explanation element-ui Step on pit record 2019PHP Interview questions ( Continuously updated )PHPJava Misunderstanding —— Method overloading is a manifestation of polymorphism ? First issue 500 100 million , Set up a new Department , What is Tencent going to do ? Google chrome The browser can't open the web page , But what if other browsers can open it ? Regression of dependent variable order categories (R language )【Golang Basic series 10 】Go language On conditional sentences if