疯狂的狮子Li
2024-01-25 4273f2db34756eb44b4b91b20cf7691c0679bf82
!485 优化 OssFactory 获取实例锁性能
Merge pull request !485 from fanc/dev
已修改1个文件
12 ■■■■■ 文件已修改
ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java 12 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-common/ruoyi-common-oss/src/main/java/org/dromara/common/oss/factory/OssFactory.java
@@ -25,6 +25,8 @@
    private static final Map<String, OssClient> CLIENT_CACHE = new ConcurrentHashMap<>();
    private static final ReentrantLock lock = new ReentrantLock();
    /**
     * 获取默认实例
     */
@@ -51,12 +53,14 @@
        OssClient client = CLIENT_CACHE.get(key);
        // 客户端不存在或配置不相同则重新构建
        if (client == null || !client.checkPropertiesSame(properties)) {
            ReentrantLock lock = new ReentrantLock();
            lock.lock();
            try {
                CLIENT_CACHE.put(key, new OssClient(configKey, properties));
                log.info("创建OSS实例 key => {}", configKey);
                return CLIENT_CACHE.get(key);
                client = CLIENT_CACHE.get(key);
                if (client == null || !client.checkPropertiesSame(properties)) {
                    CLIENT_CACHE.put(key, new OssClient(configKey, properties));
                    log.info("创建OSS实例 key => {}", configKey);
                    return CLIENT_CACHE.get(key);
                }
            } finally {
                lock.unlock();
            }