tomcatconcurrencyconnection-poolingtomcat9connection-pool

Tomcat: Creating a connection pool for cloud API services


A Tomcat server worker thread replying to an incoming request must access at least one of several possible cloud API services (Google Cloud Storage in particular; non-modifying, that is, only performing Reads). Tomcat offers out-of-the-box pooling for JDBC and JNDI compatible DB's and services. What is the best strategy for pooling connections to multiple cloud services to be shared across worker threads?


Solution

  • As you mentioned Tomcat allows defining JDBC/JNDI resources that can be used by web applications. If there is a JDBC driver available for the service you want to use then you can use the same approach. For example, a quick search for GCS JDBC driver returns this.

    For pooling, you could define HikariCP as a tomcat resource and configure it to connect to GCS using the third-party driver using the driverClassName property.

    Alternatively, applications can use the HTTP-based SDKs that cloud providers usually make available.