第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何為第三方應用程序創(chuàng)建連接池/僅創(chuàng)建一次?

如何為第三方應用程序創(chuàng)建連接池/僅創(chuàng)建一次?

蠱毒傳說 2022-08-17 16:39:44
我正在使用JAVA / Spring MVC,當我嘗試多次連接它時,我需要在我的應用程序中為第三方應用程序集成制作一個連接池,我的應用程序和服務器系統(tǒng)使用100%RAM。在這里,我必須有問題,當用戶開始多次點擊特定方法()時,我的堆內(nèi)存(RAM空間)增加并成為100%,應用程序?qū)⒕徛厥褂盟啻芜B接第三方應用程序?在這里,我只需要創(chuàng)建一次并多次獲取它。我的連接喜歡,callGenerationService()connectionpublic class ClickToCallServiceImpl implements ClickToCallServiceInterface {Client client = null;@Overridepublic ClickToCall callGenerationService(ClickToCall clickToCall) {     client = new Client();     client.connect("127.0.0.1", 8021 , "password", 10); //Every time Connection Connect.     client.setEventSubscriptions("plain", "all");     // client.sendSyncApiCommand("",""); //here i run command on every hit like.    client.sendSyncApiCommand(clickToCall.command1, clickToCall.command2);    client.close();}}這里的“ClickToCall”是一個@Component Bean/POJO類,具有變量設置器和 getters。有沒有,我們?nèi)绾蝿?chuàng)建一個用于上述連接,我只連接一次并多次點擊并利用更少的RAM?提前致謝。connection (either pool or only once connect)clickToCall.Command1 and clickToCall.Command2
查看完整描述

1 回答

?
HUX布斯

TA貢獻1876條經(jīng)驗 獲得超6個贊

請注意,我不是自由開關ESL的專家,所以你必須正確檢查代碼。無論如何,這就是我要做的。


首先,我為客戶創(chuàng)建一個工廠


public class FreeSwitchEslClientFactory extends BasePooledObjectFactory<Client> {


    @Override

    public Client create() throws Exception {

        //Create and connect: NOTE I'M NOT AN EXPERT OF ESL FREESWITCH SO YOU MUST CHECK IT PROPERLY

        Client client = new Client();

        client.connect("127.0.0.1", 8021 , "password", 10);

        client.setEventSubscriptions("plain", "all");

        return client;

    }


    @Override

    public PooledObject<Client> wrap(Client obj) {


        return new DefaultPooledObject<Client>(obj);

    }

}

然后我創(chuàng)建一個可共享的:GenericObjectPool


@Configuration

@ComponentScan(basePackages= {"it.olgna.spring.pool"})

public class CommonPoolConfig {


    @Bean("clientPool")

    public GenericObjectPool<Client> clientPool(){

        GenericObjectPool<Client> result = new GenericObjectPool<Client>(new FreeSwitchEslClientFactory());

        //Pool config e.g. max pool dimension

        result.setMaxTotal(20);

        return result;

    }

}

最后,我使用創(chuàng)建的池來獲取客戶端 obj:


@Component

public class FreeSwitchEslCommandSender {


    @Autowired

    @Qualifier("clientPool")

    private GenericObjectPool<Client> pool;


    public void sendCommand(String command, String param) throws Exception{

        Client client = null;

        try {

            client = pool.borrowObject();

            client.sendSyncApiCommand(command, param);

        } finally {

            if( client != null ) {

                client.close();

            }

            pool.returnObject(client);

        }

    }

}

我沒有測試(也是因為我不能)但它應該有效。無論如何,我祈禱您正確檢查配置。我不知道是否可以始終創(chuàng)建 Client 對象并進行連接,或者當您要發(fā)送命令時連接是否更好


我希望它能有用


編輯信息


對不起,我早點犯了一個錯誤。您必須將客戶端返回到池我更新了我的 FreeSwitchEslCommandSender 類


查看完整回答
反對 回復 2022-08-17
  • 1 回答
  • 0 關注
  • 93 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號