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,
Image format conversion Count the number of letters (java Language implementation ) Using orthogonal table method to design test cases One is called “ Asking for the train ” A small village Finally got the train VaR - Value at risk - Monte Carlo method - Python How to build data security system ?python: Convert a file to a binary file (binary)vue use vue-clipboard2 Realize the function of copy link 13. solve git Merge conflict uniapp Summary of page value transfer