I am trying to understand if I should synchronize the below factory method.I tested the code with three sample thread and I am always getting the correct object for each thread(meaning Thread 1 always shows TYPE1,thread2 always show TYPE2 and thread3 always shows TYPE3 but I am still thinking that this may not be the case always unless I synchronize the factory method else it will not be thread safe meaning thread 1 could get type 2 or type 3 also.
Also another option is moving the static field b inside method so that it will be a local variable.
Excellent. But Jayesh's other point stands. Your class field b is completely unnecessary and should be removed; it's the source of the bug you're observing. I would also recommend making the binders variable final. That's not strictly necessary for a static field, but good practice (and prevents anyone else from changing it without realizing it's supposed to be constant). If the field were non-static, then making it final would be necessary in order to access it in a thread-safe manner without synchronization.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: Thread synchronization for Static factory method