-
Notifications
You must be signed in to change notification settings - Fork 448
Closed
Labels
type: twilio enhancementfeature request on Twilio's roadmapfeature request on Twilio's roadmap
Description
Version:
7.22.0
Steps to Reproduce
The Twilio class has a bunch of multithreading issues. I fundamentally disagree with using singletons that are mutable, but if you're going to do it, it needs to be thread safe.
Here's what I recommend:
- add synchronized to all set* and init* methods . These methods are called infrequently so the synchronization penalty will be minimal
- Make the restClient and executorService fields volatile
- For getRestClient and getExecutorService we can minimize the synchronization by doing the double null check trick. Here is an example pattern on how to use it:
public static TwilioRestClient getRestClient() {
if (restClient == null) {
synchronized(Twilio.class) {
if (restClient == null) {
restClient = buildRestClient()
}
}
}
return restClient
}Metadata
Metadata
Assignees
Labels
type: twilio enhancementfeature request on Twilio's roadmapfeature request on Twilio's roadmap