Exception in thread "Thread-3" Exception in thread "Thread-0" java.lang.NumberFormatException: For input string: "1951." at java.base/java.lang.NumberFormatException.forInputString(NumberFormatException.java:65) at java.base/java.lang.Long.parseLong(Long.java:692) at java.base/java.lang.Long.parseLong(Long.java:817) at java.base/java.text.DigitList.getLong(DigitList.java:195) at java.base/java.text.DecimalFormat.parse(DecimalFormat.java:2123) at java.base/java.text.SimpleDateFormat.subParse(SimpleDateFormat.java:1933) at java.base/java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1541) at java.base/java.text.DateFormat.parse(DateFormat.java:393) at com.heu.test.TestDate.lambda$main$0(TestDate.java:21) at java.base/java.lang.Thread.run(Thread.java:834)
DateTimeFormatterdtf= DateTimeFormatter.ofPattern("yyyy-MM-dd"); for (inti=0; i < 10; i++) { newThread(() -> { LocalDatedate= dtf.parse("2018-10-01", LocalDate::from); log.debug("{}", date); }).start(); }
不可变设计
String类中不可变的体现:
1 2 3 4 5 6 7 8
publicfinalclassString implementsjava.io.Serializable, Comparable<String>, CharSequence { /** The value is used for character storage. */ privatefinalchar value[]; /** Cache the hash code for the string */ privateint hash; // Default to 0 // ... }