package org.jcoffee.serialization;

import java.util.HashMap;
import java.util.Map;

public class SerializerFactory {

    private static final Map<Class, SerializerUnsafeI> SERIALIZER_UNSAFE_MAP = new HashMap<>();

    private SerializerFactory() {}

    @SuppressWarnings("unchecked")
    public static <T> SerializerUnsafeI<T> getSerializer(Class<T> clazz) {
        if (!SERIALIZER_UNSAFE_MAP.containsKey(clazz)) {
            synchronized (SERIALIZER_UNSAFE_MAP) {
                if (!SERIALIZER_UNSAFE_MAP.containsKey(clazz)) {
                    SERIALIZER_UNSAFE_MAP.put(clazz, new SerializerUnsafe<>(clazz));
                }
            }
        }
        return SERIALIZER_UNSAFE_MAP.get(clazz);
    }
}

@@ -76,16 +76,105 @@
 til.Map;
+%0Aimport java.util.concurrent.locks.Lock;%0Aimport java.util.concurrent.locks.ReentrantLock;
 %0A%0Apublic
@@ -298,16 +298,75 @@
 p%3C%3E();%0A%0A
+    private static final Lock LOCK = new ReentrantLock();%0A%0A
     priv
@@ -390,16 +390,21 @@
 tory() %7B
+%0A    
 %7D%0A%0A    @
@@ -581,46 +581,42 @@
     
-synchronized (SERIALIZER_UNSAFE_MAP) %7B
+try %7B%0A                LOCK.lock();
 %0A   
@@ -762,16 +762,16 @@
 lazz));%0A
-
         
@@ -772,32 +772,87 @@
               %7D%0A
+            %7D finally %7B%0A                LOCK.unlock();%0A
             %7D%0A  

use lock instead synchronized