« Return to Thread: XsdUtils.getLocalTimeString not thread safe

XsdUtils.getLocalTimeString not thread safe

by sunh11373 :: Rate this Message:

Reply to Author | View in Thread


The XsdUtils class uses a static SimpleDateFormat object to format date objects (see below). According to JDK:

>>>
Synchronization

Date formats are not synchronized. It is recommended to create separate format instances for each thread. If multiple threads access a format concurrently, it must be synchronized externally.
<<<

We did observe strange exceptions from that class when the code runs in multi-threaded environment. This forces us to put a hard sync. on unmarshal ManagementEvent objects.

Can this be fixed quickly?

-thanks




------
public class XsdUtils
{
    //
    // Used to format dates in the XMLSchema dateTime format
    //
    private static DateFormat _FORMATTER =
        new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
   

 « Return to Thread: XsdUtils.getLocalTimeString not thread safe