Skip to content

🎨新增okhttp单例模式,减少多租户情况下okhttp实例#2934

Merged
binarywang merged 1 commit intobinarywang:developfrom
wulangcode:develop
Feb 18, 2023
Merged

🎨新增okhttp单例模式,减少多租户情况下okhttp实例#2934
binarywang merged 1 commit intobinarywang:developfrom
wulangcode:develop

Conversation

@wulangcode
Copy link

image
多租户场景下,okhttp实例过多,代码如下:

    public BaseWxCpServiceImpl getWxCpServiceByCorpId(String corpId) {
        BaseWxCpServiceImpl wxCpServiceOnTp = WX_CP_SERVICE_ON_TP_MAP.get(corpId);
        if (wxCpServiceOnTp == null) {
            synchronized (WX_CP_SERVICE_ON_TP_MAP) {
                wxCpServiceOnTp = WX_CP_SERVICE_ON_TP_MAP.get(corpId);
                if (wxCpServiceOnTp == null) {
                    // 在这里每次都会new出一个新的okhttp实例,完全可以减少个数
                    wxCpServiceOnTp = new WxCpServiceOkHttpImpl();
                    MyWxCpConfigImpl myWxCpRedisConfig = new MyWxCpConfigImpl(corpId, redisHelper.getPool(),
                            WorkWxConfig.getWorkWxProperties(), workwxAuthRepository);
                    wxCpServiceOnTp.setWxCpConfigStorage(myWxCpRedisConfig);
                    WX_CP_SERVICE_ON_TP_MAP.put(corpId, wxCpServiceOnTp);
                }
            }
        }
        return wxCpServiceOnTp;
    }

@binarywang binarywang merged commit b834352 into binarywang:develop Feb 18, 2023
@binarywang binarywang added this to the 4.4.9 milestone Mar 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants