Duplicate :
|
FULL PRODUCT VERSION : 1.6.0_01 ADDITIONAL OS VERSION INFORMATION : XP professional 2002 with service pack 2 A DESCRIPTION OF THE PROBLEM : java.text.SimpleDateFormat.parse method does not works thread safe. when i want to use single instance of SimpleDateFormat class for multi thread applications, sometimes .parse method throws excetion...... STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : executable code block can be use for EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - when i want to use this class as singleton i should not got exceptions ACTUAL - i got exceptions .... ERROR MESSAGES/STACK TRACES THAT OCCUR : java.lang.NumberFormatException: For input string: "" at java.lang.NumberFormatException.forInputString(Unknown Source) at java.lang.Long.parseLong(Unknown Source) at java.lang.Long.parseLong(Unknown Source) at java.text.DigitList.getLong(Unknown Source) at java.text.DecimalFormat.parse(Unknown Source) at java.text.SimpleDateFormat.subParse(Unknown Source) at java.text.SimpleDateFormat.parse(Unknown Source) at java.text.DateFormat.parse(Unknown Source) REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.text.SimpleDateFormat; public class alll { public static void main(String[] args) throws Exception { SimpleDateFormat simpleDateFormat = new SimpleDateFormat("ddMMyyyyHHmm" ) ; Tester[] tester = new Tester[10]; for (int i = 0; i < 10; i++) { tester[i] = new Tester(simpleDateFormat); tester[i].start(); } } /** * */ private static class Tester extends Thread{ SimpleDateFormat sp = null; public Tester(SimpleDateFormat simpleDateFormat ){ this.sp = simpleDateFormat; } public void run(){ while(true){ try { System.out.println(sp.parse("010120070101")); } catch (Exception e) { e.printStackTrace(); } } } } } ---------- END SOURCE ----------