class SharedObjectPool {

    public T get(T input)
    {
        myReadLock.lock();
        try
        {
            WeakReference<T> ref = myPool.get(input);
            T poolObject = ref == null ? null : ref.get();
            if (poolObject != null)
            {
                return poolObject;
            }
        }
        finally
        {
            myReadLock.unlock();
        }

        myWriteLock.lock();
        try
        {
            WeakReference<T> ref = myPool.get(input);
            T poolObject = ref == null ? null : ref.get();
            if (poolObject == null)
            {
                myPool.put(input, new WeakReference<>(input));
                poolObject = input;
            }

            return poolObject;
        }
        finally
        {
            myWriteLock.unlock();
        }
    }

}