JDBC connection pool compatible with App Engine

◇◆丶佛笑我妖孽 提交于 2019-12-04 03:01:21

I had to use Tomcat DBCP 1.4 (older version), because of the GAE frontend not allowing threads to live outside of request scope. Here's an example project: https://github.com/kennberg/appengine-java-connection-pool

Note that the connection pool is necessary once you have too many requests, because there is a limit on number of pending connections per instance. Re-using connections helps stay under the limit.

You probably don't need connection pooling at all:

https://cloud.google.com/sql/faq#connections

... if the time to create a new connection is about the same as testing if an existing connection is alive and reusing it, then we recommend that you create a new connection to service each HTTP request, and reuse it for the duration of the request. In particular, the latter case may apply when you connect from Google App Engine to Google Cloud SQL.

You may be getting the AccessControlException because your application is set to "Automatic Scaling".

It used to be that a GAE app could be a "backend" or a "frontend" and only backends could use background threads. Now with backends deprecated and replaced with modules, the use of background threads is tied to the scaling type of the app.

https://cloud.google.com/appengine/docs/java/modules/#Java_Background_threads

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