I tried to replicate the error using the same instance of SimpleDateFormat for multiple threads. However, I ran into another problem and did not find any answers on it.
This simple block of code replicates the problems that I see.
DateFormat d1 = new SimpleDateFormat("ddMMyyyy"); DateFormat d2 = new SimpleDateFormat("ddMMyyyy"); DateFormat d3 = new SimpleDateFormat("ddMMyy"); System.out.println("d1 = " + d1); System.out.println("d2 = " + d2); System.out.println("d3 = " + d3);
The results of these operations under java 7 (1.7_0_21) are as follows
d1 = java.text.SimpleDateFormat@c5bfbc60 d2 = java.text.SimpleDateFormat@c5bfbc60 d3 = java.text.SimpleDateFormat@b049fd40
As you can see, although I am creating new objects for d1 and d2, they eventually become the same reference. d3 ends up being a new instance since the pattern is different.
Does java compile / run-time this optimization? Any pointers would be helpful
java
rixmath
source share