I had a problem where the JUnit test failed when building outside of eclipse (via DOS ANT build and test script), but it worked fine inside eclipse.
Under the test code was a class and a method from a batch job in which SimpleDateFormat was declared a private static final.
I did not like thread safety because this is a single-threaded batch job.
I also did not want to create an instance of SimpleDateFormat every time I needed it, because the process was processing cycles of thousands of rows of data.
I got around this by changing the declaration of SimpleDateFormat from a private static final to a private final transient.
Of course, this means creating an instance of the class, which may not work for all cases, but this is the solution if you create an instance of the class and do not want to create new instances every time, and thread safety is not a problem.
source share