@@ -0,0 +1,2219 @@
+package ru.aifgi.recognizer.model;%0A%0A/*%0A * Copyright 2012 Alexey Ivanov%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A * http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A%0Aimport com.google.common.collect.MapMaker;%0A%0Aimport java.util.concurrent.ConcurrentMap;%0Aimport java.util.concurrent.locks.Lock;%0Aimport java.util.concurrent.locks.ReadWriteLock;%0Aimport java.util.concurrent.locks.ReentrantReadWriteLock;%0A%0A/**%0A * @author aifgi%0A */%0A%0Apublic class ReadWriteLocker %7B%0A    private static volatile ReadWriteLocker ourLocker;%0A%0A    public static ReadWriteLocker getInstance() %7B%0A        if (ourLocker == null) %7B%0A            synchronized (ReadWriteLocker.class) %7B%0A                if (ourLocker == null) %7B%0A                    ourLocker = new ReadWriteLocker();%0A                %7D%0A            %7D%0A        %7D%0A        return ourLocker;%0A    %7D%0A%0A    private final ConcurrentMap%3CObject, ReadWriteLock%3E myLocks;%0A%0A    private ReadWriteLocker() %7B%0A        myLocks = new MapMaker().concurrencyLevel(16).weakKeys().makeMap();%0A    %7D%0A%0A    public Lock getReadLock(final Object o) %7B%0A        final ReadWriteLock readWriteLock = getLockForObject(o);%0A        return readWriteLock.readLock();%0A    %7D%0A%0A    public Lock getWriteLock(final Object o) %7B%0A        final ReadWriteLock readWriteLock = getLockForObject(o);%0A        return readWriteLock.writeLock();%0A    %7D%0A%0A    private ReadWriteLock getLockForObject(final Object o) %7B%0A        ReadWriteLock readWriteLock = myLocks.get(o);%0A        if (readWriteLock == null) %7B%0A            final ReentrantReadWriteLock value = new ReentrantReadWriteLock(true);%0A            readWriteLock = myLocks.putIfAbsent(o, value);%0A            if (readWriteLock == null) %7B%0A                readWriteLock = value;%0A            %7D%0A        %7D%0A        return readWriteLock;%0A    %7D%0A%7D%0A

read write locker