Will two threads access the same instance of the converter object in JSF at the same time?
Depending on how you use the converter. If you use
<h:inputWhatever> <f:converter converterId="converterId" /> </h:inputWhatever>
then a new instance will be created for each input element in the view, which is thread safe (expect from a very rare case of the edge when enduser has two identical views on two browser tabs in one session and at the same time returns a postback to both views).
If you use
<h:inputWhatever converter="#{applicationBean.converter}" />
then the same instance will be shared in all representations of the entire application, which, therefore, is not thread safe.
However, you clone a static instance of DataFormat every time you create a converter. This part is no longer thread safe. You may risk that you are cloning an instance, and its internal state has been changed because it was used elsewhere. In addition, cloning an existing instance is not necessarily cheaper than creating a new instance.
I would recommend just declaring it threadlocal (i.e. inside the method block), regardless of how you use the converter. If the costly creation of DateFormat every time is a serious problem (are you his profile?), Then consider replacing it with JodaTime .
source share