-
Notifications
You must be signed in to change notification settings - Fork 350
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* The static method java.lang.ThreadLocal.withInitial is added On line 99 * Added ThreadLocalTest to "src/tests" * Imports are removed and added a newline character (line break)
- Loading branch information
1 parent
07fd626
commit f8b4549
Showing
2 changed files
with
26 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import java.sql.Date; | ||
import java.text.SimpleDateFormat; | ||
|
||
class threadSafeFormatter{ | ||
public static ThreadLocal<SimpleDateFormat> df = ThreadLocal.withInitial(() | ||
-> new SimpleDateFormat("yyyy-MM-dd")); | ||
} | ||
|
||
public class App { | ||
public static void main(String[] args) throws Exception { | ||
threadSafeFormatter tf = new threadSafeFormatter(); | ||
Thread t1 = new Thread(); | ||
t1.start(); | ||
} | ||
|
||
public static String birthDate(int userId){ | ||
Date birthdDate = new Date(userId); | ||
final SimpleDateFormat df = threadSafeFormatter.df.get(); | ||
return df.format(birthdDate); | ||
} | ||
} |