Twilio Threaded Messages

穿精又带淫゛_ 提交于 2019-12-11 10:03:17

问题


If I want to kick off a thread that will be sending a text message with twilio, is it better to do

TwilioRestClient client = new TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN);

for each thread or should I make one client and share it with the threads?


回答1:


You can see the source code for TwilioRequestClient class of the twilio-java helper library here: https://github.com/twilio/twilio-java/blob/master/src/main/java/com/twilio/sdk/TwilioRestClient.java

I don't see anything not obviously thread-safe. My only concern would be this part of the code in the constructor:

//Grab the proper connection manager, based on runtime environment
ClientConnectionManager mgr = null;
try {
    Class.forName("com.google.appengine.api.urlfetch.HTTPRequest");
    mgr = new AppEngineClientConnectionManager();
} catch (ClassNotFoundException e) {
    //Not GAE
    mgr = new ThreadSafeClientConnManager();
    ((ThreadSafeClientConnManager) mgr).setDefaultMaxPerRoute(10);
}

It generates a new thread pool for every initialization, so I'd say share the resource. On the other hand, will it have enough connections available to efficiently handle your load?

You can read up more about ThreadSafeClientConnManager here: https://hc.apache.org/httpcomponents-client-4.3.x/httpclient/apidocs/org/apache/http/impl/conn/tsccm/ThreadSafeClientConnManager.html#setDefaultMaxPerRoute%28int%29

Bottom line, try load testing it with your expected usage and tweak the source to meet your needs.



来源:https://stackoverflow.com/questions/23016255/twilio-threaded-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!