mirror of https://github.com/apache/cassandra
make json date formatter thread safe
patch by dbrosius reviewed by thobbs for CASSANDRA-10814
This commit is contained in:
parent
8565ca89a9
commit
ebbd516985
|
|
@ -82,7 +82,7 @@ public class DateType extends AbstractType<Date>
|
|||
@Override
|
||||
public String toJSONString(ByteBuffer buffer, int protocolVersion)
|
||||
{
|
||||
return '"' + TimestampSerializer.TO_JSON_FORMAT.format(TimestampSerializer.instance.deserialize(buffer)) + '"';
|
||||
return '"' + TimestampSerializer.getJsonDateFormatter().format(TimestampSerializer.instance.deserialize(buffer)) + '"';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ public class TimestampType extends AbstractType<Date>
|
|||
@Override
|
||||
public String toJSONString(ByteBuffer buffer, int protocolVersion)
|
||||
{
|
||||
return '"' + TimestampSerializer.TO_JSON_FORMAT.format(TimestampSerializer.instance.deserialize(buffer)) + '"';
|
||||
return '"' + TimestampSerializer.getJsonDateFormatter().format(TimestampSerializer.instance.deserialize(buffer)) + '"';
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -96,8 +96,14 @@ public class TimestampSerializer implements TypeSerializer<Date>
|
|||
}
|
||||
};
|
||||
|
||||
public static final SimpleDateFormat TO_JSON_FORMAT = new SimpleDateFormat(dateStringPatterns[15]);
|
||||
|
||||
private static final ThreadLocal<SimpleDateFormat> FORMATTER_TO_JSON = new ThreadLocal<SimpleDateFormat>()
|
||||
{
|
||||
protected SimpleDateFormat initialValue()
|
||||
{
|
||||
return new SimpleDateFormat(dateStringPatterns[15]);
|
||||
}
|
||||
};
|
||||
|
||||
public static final TimestampSerializer instance = new TimestampSerializer();
|
||||
|
||||
public Date deserialize(ByteBuffer bytes)
|
||||
|
|
@ -138,6 +144,11 @@ public class TimestampSerializer implements TypeSerializer<Date>
|
|||
throw new MarshalException(String.format("Unable to coerce '%s' to a formatted date (long)", source), e1);
|
||||
}
|
||||
}
|
||||
|
||||
public static SimpleDateFormat getJsonDateFormatter()
|
||||
{
|
||||
return FORMATTER_TO_JSON.get();
|
||||
}
|
||||
|
||||
public void validate(ByteBuffer bytes) throws MarshalException
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue