Replaced synchronized with ThreadLocal

Yes, this looks better

On Tue, Dec 16, 2014 at 4:25 AM, Phil Kallos <notifications@github.com>
wrote:
>
> In
> 2-collectors/scala-stream-collector/src/main/scala/com.snowplowanalytics.snowplow.collectors.scalastream/sinks/AbstractSink.scala
> <https://github.com/snowplow/snowplow/pull/1254#discussion-diff-21840818>:
>
> > @@ -36,9 +36,13 @@ trait AbstractSink {
> >    // Serialize Thrift SnowplowRawEvent objects,
> >    // and synchronize because TSerializer doesn't support multi-threaded
> >    // serialization.
> > -  private val thriftSerializer = new TSerializer
> > -  def serializeEvent(event: SnowplowRawEvent): Array[Byte] =
> > -    this.synchronized {
> > -      thriftSerializer.serialize(event)
> > +  private val thriftSerializer = new ThreadLocal[TSerializer]
>
> How about instead
>
> private val thriftSerializer = new ThreadLocal[TSerializer] {
>  override def initialValue = new TSerializer()
> }
>
> So the initialization is handled outside of the serializeEvent code?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/snowplow/snowplow/pull/1254/files#r21840818>.
>