Skip to content

Commit

Permalink
测试ThreadLocal
Browse files Browse the repository at this point in the history
  • Loading branch information
cdtft committed May 12, 2020
1 parent 5b3adb1 commit 5f17a06
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/main/java/com/cdtft/leetcode/Solution.java
@@ -1,7 +1,9 @@
package com.cdtft.leetcode;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -414,12 +416,18 @@ public int majorityElement_1(int[] nums) {
return cand;
}

private static final ThreadLocal<SimpleDateFormat> formatter = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
return new SimpleDateFormat("yyyyMMdd HHmm");
}
};

public static void main(String[] args) {
LinkedList<Integer> list = new LinkedList<>();
list.push(1);
list.add(2);
System.out.println(list.poll());
System.out.println("");
new Thread(() -> {
SimpleDateFormat format = formatter.get();
System.out.println(format.format(new Date()));
}).start();
}

}

0 comments on commit 5f17a06

Please sign in to comment.