⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simplepool.java

📁 Xfire文件 用于开发web service 的一个开源工具 很好用的
💻 JAVA
字号:
package org.codehaus.xfire.util.factory;

/**
 * A simple implementation of Pool that uses null to indicate non-existent pool
 * entry.
 * <p>
 * This implementation synchronizes on {@link #getMutex()} for thread safety.
 * </p>
 * 
 * @author Ben Yu Feb 2, 2006 3:14:45 PM
 */
public abstract class SimplePool
    implements Pool
{
    public Object getInstance(Factory factory)
        throws Throwable
    {
        synchronized (getMutex())
        {
            Object ret = get();
            if (ret == null)
            {
                ret = factory.create();
                set(ret);
            }
            return ret;
        }
    }

    public Object getPooledInstance(Object def)
    {
        synchronized (getMutex())
        {
            return ifnull(get(), def);
        }
    }

    public boolean isPooled()
    {
        synchronized (getMutex())
        {
            return get() != null;
        }
    }

    protected static Object ifnull(Object obj, Object def)
    {
        return obj == null ? def : obj;
    }

    /**
     * Get the pooled instance. null if not found.
     * 
     * @return the pooled instance.
     */
    public abstract Object get();

    /**
     * set an value to the pool.
     * 
     * @param val
     *            the value to be pooled.
     */
    public abstract void set(Object val);

    /**
     * Get the object that can be used to synchronize.
     */
    protected abstract Object getMutex();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -